Deployment

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-

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值