2

k8s 基本概念理解

 3 years ago
source link: http://www.chenshake.com/k8s-basic-conceptual-understanding-of-the-basic-concepts-of/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

 

其实用了k8s很久,但是很多概念的理解,有时候真的需要动手,才能真正理解。

官方文档提供的nginx的deployment模版,我修改一下,采用alpine镜像,副本的数量为1

nginx.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: default
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80

有几个地方需要留意

  • deployment 名字是 nginx-deployment, 后续你可以用 kubectl get svc 看到
  • labels, 标签是:nginx,
  • namespace 如果不指定,就是使用default,我这里专门加入,便于理解。
  • 部署pod的数量是1
  • nginx的alpine镜像,小很多,方便试验。
kubectl apply -f nginx.yaml 
kubectl get pod
kubectl get deployment
kubectl get svc
kubectl expose deployment nginx-deployment --type=NodePort --name=hello
kubectl get svc
kubectl describe svc hello

 Posted by 陈沙克 at 11:41 AM

 Leave a Reply Cancel reply

Your Comment

Name (required)

E-mail (required)

Website

Save my name, email, and website in this browser for the next time I comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK