Deployment

自作多情 提交于 2020-01-21 15:23:26

Deployment


apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-web
spec:
  replicas: 4
  template:
    metadata:
      labels:
        app:  web
   spec:
     containers:
     - name: test-web
       image:  192.168.1.70:5000/httpd:v1
       ports:
       - containerPort:  80

PS:注意,在Deployment资源对象中,可以添加Port字段,但此字段仅供用户查看,并不实际生效

service


 

kind: Service
apiVersion: v1
metadata:
  name: web-svc
spec:
  type: NodePort
  selector:
    app:  web
  ports:
  - protocol: TCP
    port: 80  //clusterIP的端口
    targetPort: 80  //Pod的端口
    nodePort: 30123

SNAT:Source NAT(源地址转换)

DNAT:Destination NAT(目标地址转换)

MASQ:动态的源地址转换

 

service实现的负载均衡:默认使用的是iptables规则

第二种方案:IPVS

回滚到指定版本


准备三个版本所使用的私有镜像,来模拟每次升级到不同的镜像

Deployment1.yaml

[root@master ~]# vim  deployment1.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-web
spec:
  revisionHistoryLimit: 10
  replicas: 3
  template:
    metadata:
      labels:
        app:  web
    spec:
      containers:
      - name: test-web
        image:  192.168.1.70:5000/httpd:v1
        ports:

Deployment2.yaml

[root@master ~]# vim  deployment2.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-web
spec:
  revisionHistoryLimit: 10
  replicas: 3
  template:
    metadata:
      labels:
        app:  web
    spec:
      containers:
      - name: test-web
        image:  192.168.1.70:5000/httpd:v2
        ports:
        - containerPort:  80

Deployment3.yaml

[root@master ~]# vim  deployment3.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-web
spec:
  revisionHistoryLimit: 10
  replicas: 3
  template:
    metadata:
      labels:
        app:  web
    spec:
      containers:
      - name: test-web
        image:  192.168.1.70:5000/httpd:v3
        ports:
        - containerPort:  80

此处3个yaml文件,指定不同版本的镜像

 

//运行一个服务,并记录一个版本信息

[root@master ~]# kubectl apply  -f  deployment1.yaml  --record

//查看有哪些版本信息

[root@master ~]# kubectl  rollout history deployment test-web

//运行并升级Deployment资源,并记录版本信息

[root@master ~]# kubectl  apply  -f  deployment2.yaml --record
[root@master ~]# kubectl  apply  -f  deployment3.yaml --record

//此时可以运行一个关联的Service资源去验证升级是否成功

[root@master ~]# kubectl  apply -f  web-svc.yaml
[root@master ~]# curl  10.96.179.50
<h1>zhb | test-web | httpd | v3<h1>

//回滚到指定版本

用label控制Pod的位置


//添加节点你标签

[root@master ~]# kubectl label nodes node02 disk=ssd
[root@master ~]# kubectl get nodes --show-labels | grep node02
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-web
spec:
  revisionHistoryLimit: 10  //版本历史限制
  replicas: 3
  template:
    metadata:
      labels:
        app:  web
    spec:
      containers:
      - name: test-web
        image:  192.168.1.70:5000/httpd:v1
        ports:
        - containerPort:  80
      nodeSelector:  //添加节点选择器
        disk: ssd   //和标签内容一致

 

[root@master ~]# kubectl  get  pod  -o  wide
NAME                       READY   STATUS    RESTARTS   AGE   IP            NODE     NOMINATED NODE   READINESS GATES
test-web-d58c9f847-bhswj   1/1     Running   0          28s   10.244.2.14   node02   <none>           <none>
test-web-d58c9f847-k58nj   1/1     Running   0          28s   10.244.2.13   node02   <none>           <none>
test-web-d58c9f847-vt7r5   1/1     Running   0          28s   10.244.2.15   node02   <none>           <none>

//删除节点标签

[root@master ~]# kubectl  label nodes node02  disk-

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!