02.kubernetes笔记 Pod控制器(一) ReplicaSet

控制器简介

Kubernetes 中内建了很多 controller(控制器),这些相当于一个状态机,用来控制 Pod 的具体状态和行为

  • 负责应用编排的控制器类型有如下几种:
  • ReplicationController:最早期的Pod控制器;
  • RelicaSet: 副本集,负责管理一个应用(Pod)的多个副本;
  • Deployment: 部署,它不直接管理Pod,而是借助于ReplicaSet来管理Pod;最常用的无状态应用控制器;
  • DaemonSet:守护进程集,用于确保在每个节点仅运行某个应用的一个Pod副本;
  • StatefulSet:功能类似于Deployment,但StatefulSet专用于编排有状态应用;
  • Job:有终止期限的一次性作业式任务,而非一直处于运行状态的服务进程;
  • CronJob:有终止期限的周期性作业式任务;

ReplicaSet 简介

  • ReplicationController 和 ReplicaSet
    ReplicationController(RC)用来确保容器应用的副本数始终保持在用户定义的副本数,即如果有容器异常退
    出,会自动创建新的 Pod 来替代;而如果异常多出来的容器也会自动回收;
    在新版本的 Kubernetes 中建议使用 ReplicaSet 来取代 ReplicationController 。ReplicaSet 跟
    ReplicationController 没有本质的不同,只是名字不一样,并且 ReplicaSet 支持集合式的 selector;
  • Pod控制器定义要素:
  • 标签选择器;
  • 期望的副本数;
  • Pod模板;
  • ReplicaSet的更新机制:
    删除式更新
    比如:- set image:更新应用版本,但对于replicaset来说,仅能更新API Server中的定义 实际运行Pod只能删除后重新启动才生效

Replicaset 字段说明

apiversion: apps/v1
kind: Replicaset
metadata:
  name: ...
  namespace: …
spec:
  minReadySeconds   #Pod就绪后多少秒内任一容器无crash方可视为“就绪”
  replicas  #期望的Pod副本数,默认为1
  selectorl:  #标签选择器,必须匹配template字段中Pod模板中的标签;
    matchExpressions_<[ ]Object> #标签选择器表达式列表,多个列表项之间为“与"关系 
    matchLabels  #map格式的标签选择器;和之前SVC的标签选择器为selector:类似
  template: #Pod模板对象
    metadata: #Pod对象元数据
      labels: #由模板创建出的Pod对象所拥有的标签,必须要能够匹配前面定义的标签选择器
      spec:# Pod规范,格式同自主式Pod
       ......

示例1:创ReplicaSet控制器

[root@k8s-master PodControl]# cat replicaset.demo.yaml 
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-demo
spec:
  minReadySeconds: 3
  replicas: 2
  selector:
    matchLabels:
      app: demoapp
      release: stable
      version: v1.0
  template:
    metadata:
      labels:   #这里的标签要能覆盖住上面的标签,可以比上面多但不能比上面少,因为理论上控制器如果匹配不到Pod 控制器会无限创建Pod,实际是建创时会报错
        app: demoapp
        release: stable
        version: v1.0
        test: test22
    spec:
      containers:
      - name: demoapp
        image: ikubernetes/demoapp:v1.0
        ports:
        - name: http
          containerPort: 80
        livenessProbe:
          httpGet:
            path: '/livez'
            port: 80
          initialDelaySeconds : 10
        readinessProbe:
          httpGet:
            path: '/readyz'
            port: 80
          initialDelaySeconds: 15


[root@k8s-master PodControl]# kubectl get replicaset -o wide
NAME                    DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES                     SELECTOR
replicaset-demo         2         2         2       30m   demoapp      ikubernetes/demoapp:v1.0   app=demoapp,release=stable,version=v1.0

[root@k8s-master PodControl]# kubectl get pod -o wide
NAME                          READY   STATUS    RESTARTS   AGE   IP             NODE        NOMINATED NODE   READINESS GATES
my-grafana-7d788c5479-4ztb7   1/1     Running   0          44m   10.244.1.208   k8s-node1              
replicaset-demo-b4hx9         1/1     Running   0          34m   10.244.1.210   k8s-node1              
replicaset-demo-zb7m5         1/1     Running   1          34m   10.244.2.203   k8s-node2              

#查看描述信息
[root@k8s-master PodControl]# kubectl describe replicasets/replicaset-demo
Name:         replicaset-demo
Namespace:    default
Selector:     app=demoapp,release=stable,version=v1.0
Labels:       
Annotations:  
Replicas:     2 current / 2 desired  #现在运行 /  期望运行  
Pods Status:  2 Running / 0 Waiting / 0 Succeeded / 0 Failed  #Pod状态
Pod Template:
  Labels:  app=demoapp
           release=stable
           test=test22
           version=v1.0
  Containers:
   demoapp:
    Image:        ikubernetes/demoapp:v1.0
    Port:         80/TCP
    Host Port:    0/TCP
    Liveness:     http-get http://:80/livez delay=10s timeout=1s period=10s #success=1 #failure=3
    Readiness:    http-get http://:80/readyz delay=15s timeout=1s period=10s #success=1 #failure=3
    Environment:  
    Mounts:       
  Volumes:        
Events:
  Type    Reason            Age    From                   Message
  ----    ------            ----   ----                   -------
  Normal  SuccessfulCreate  8m28s  replicaset-controller  Created pod: replicaset-demo-b4hx9
  Normal  SuccessfulCreate  8m28s  replicaset-controller  Created pod: replicaset-demo-zb7m5


[root@k8s-master PodControl]# kubectl get pod replicaset-demo-zb7m5 -o yaml
...
ownerReferences:     #查看Pod受哪个管理器管理
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: ReplicaSet
    name: replicaset-demo
    uid: d6525139-a5a5-4886-9c2b-d7cfe2db6d35
  resourceVersion: "8790580"
  selfLink: /api/v1/namespaces/default/pods/replicaset-demo-zb7m5
...
  • ReplicaSet更新 可使用kubectl set命令更新
[root@k8s-master PodControl]# kubectl set image --help   #查看set更新的相关案例
Update existing container image(s) of resources.

 Possible resources include (case insensitive):

  pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), replicaset (rs)

Examples:
  # Set a deployment's nginx container image to 'nginx:1.9.1', and its busybox container image to
'busybox'.
  kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1
  
  # Update all deployments' and rc's nginx container's image to 'nginx:1.9.1'
  kubectl set image deployments,rc nginx=nginx:1.9.1 --all
  
  # Update image of all containers of daemonset abc to 'nginx:1.9.1'
  kubectl set image daemonset abc *=nginx:1.9.1
  
  # Print result (in yaml format) of updating nginx container image from local file, without hitting
the server
  • 更新image镜像
[root@k8s-master PodControl]# kubectl set image replicasets/replicaset-demo demoapp=ikubernetes/demoapp:v1.1   #更新replicasets中镜像版本为v1.1
replicaset.apps/replicaset-demo image updat

[root@k8s-master PodControl]# kubectl get pod -o wide
NAME                          READY   STATUS    RESTARTS   AGE   IP             NODE        NOMINATED NODE   READINESS GATES
my-grafana-7d788c5479-4ztb7   1/1     Running   0          44m   10.244.1.208   k8s-node1              
replicaset-demo-b4hx9         1/1     Running   0          34m   10.244.1.210   k8s-node1              
replicaset-demo-zb7m5         1/1     Running   1          34m   10.244.2.203   k8s-node2              

[root@k8s-master PodControl]# kubectl get replicaset/replicaset-demo -o yaml|grep image
      ...
      - image: ikubernetes/demoapp:v1.1
        imagePullPolicy: IfNotPresent

#可以看到replicaset中的镜像信息已经更新成功
[root@k8s-master PodControl]# kubectl get pods replicaset-demo-zb7m5 -o yaml  

containerStatuses:
  - containerID: docker://4c4e576d7f5accb89c4f73a0aef18bd99cac37ee81b34a07a363d2afc35d5189
    image: ikubernetes/demoapp:v1.0
    imageID: docker-pullable://ikubernetes/demoapp@sha256:6698b205eb18fb0171398927f3a35fe27676c6bf5757ef57a35a4b055badf2c3

#但Pod中的image并没有更新
[root@k8s-master PodControl]# curl 10.244.1.210  
iKubernetes demoapp v1.0 !! ClientIP: 10.244.0.0, ServerName: replicaset-demo-b4hx9, ServerIP: 10.244.1.210!
[root@k8s-master PodControl]# curl 10.244.1.210
iKubernetes demoapp v1.0 !! ClientIP: 10.244.0.0, ServerName: replicaset-demo-b4hx9, ServerIP: 10.244.1.210!

#实际访问Pod 也并没有更新成功 这是因为ReplicaSet为删除式更新 Pod删除重启后才会生效
[root@k8s-master PodControl]# kubectl delete pod -l app=demoapp,release=stable
pod "replicaset-demo-b4hx9" deleted
pod "replicaset-demo-zb7m5" deleted

[root@k8s-master PodControl]# kubectl get pod -o wide
NAME                          READY   STATUS    RESTARTS   AGE     IP             NODE        NOMINATED NODE   READINESS GATES
my-grafana-7d788c5479-4ztb7   1/1     Running   0          57m     10.244.1.208   k8s-node1              
replicaset-demo-686fl         0/1     Running   1          2m28s   10.244.1.212   k8s-node1              
replicaset-demo-k4pq9         0/1     Running   0          2m28s   10.244.3.49    k8s-node3              

[root@k8s-master PodControl]# curl 10.244.3.49   #更新成功
iKubernetes demoapp v1.1 !! ClientIP: 10.244.0.0, ServerName: replicaset-demo-k4pq9, ServerIP: 10.244.3.49!
[root@k8s-master PodControl]# curl 10.244.3.49  
iKubernetes demoapp v1.1 !! ClientIP: 10.244.0.0, ServerName: replicaset-demo-k4pq9, ServerIP: 10.244.3.49

服务部署 蓝绿发布、滚动更新

Pod部署类型:
蓝绿发布: 在旧版本的基础上 在新建一套新版本

     优点:回滚方便 可以把新旧版本完全切换 
     缺点:因为需要重新创建一套服务,更新中需要会占用更多的系统资源,切换途中流量可能会中断

滚动更新: 新增一个新版Pod在删除一个旧版Pod;或删除一个旧版Pod在新增一个新版Pod

     优点:升级过程对系统资源需要更少;可以保证流量不间断
     缺点: 新旧版本同时存在,回滚麻烦

示例2:滚动发布

[root@k8s-master PodControl]# cat replicaset.demo.yaml 
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-demo
spec:
  minReadySeconds: 3
  replicas: 2
  selector:
    matchLabels:
      app: demoapp
      release: stable
      version: v1.0
  template:
    metadata:
      labels:   
        app: demoapp
        release: stable
        version: v1.0
        test: test22
    spec:
      containers:
      - name: demoapp
        image: ikubernetes/demoapp:v1.0
        ports:
        - name: http
          containerPort: 80

[root@k8s-master PodControl]# cat service-for-replicaset-demo.yaml   #创建对应的svc 注意SVC标签需要能同时匹配新旧版本
apiVersion: v1
kind: Service
metadata:
  name: demoapp
  namespace: default
spec:
  type: ClusterIP
  clusterIP: 10.97.26.1
  selector:    #滚动升级 SVC使用的标签需要能同时匹配新旧版本
    app: demoapp
    release: stable
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80

[root@k8s-master PodControl]# kubectl apply -f replicaset.demo.yaml  -f service-for-replicaset-demo.yaml

[root@k8s-master PodControl]# kubectl get pod
NAME                    READY   STATUS    RESTARTS   AGE
pod-18865               1/1     Running   0          16m
replicaset-demo-d8jm9   1/1     Running   0          2m14s
replicaset-demo-xtz2n   1/1     Running   0          2m14s


iKubernetes demoapp v1.0 !! ClientIP: 10.244.0.0, ServerName: replicaset-demo-d8jm9, ServerIP: 10.244.1.218!
[root@k8s-master PodControl]# curl 10.97.26.1
iKubernetes demoapp v1.0 !! ClientIP: 10.244.0.0, ServerName: replicaset-demo-xtz2n, ServerIP: 10.244.2.204!
[root@k8s-master PodControl]# curl 10.97.26.1
  • 别起一个终端创建Pod 用作测试
[root@k8s-master ~]# kubectl run pod-$RANDOM --image=ikubernetes/admin-box:latest -it --rm --command -- /bin/sh   #创建一个Pod 用作测试
root@pod-18865 # while true; do curl --connect-timeout 1 demoapp.default.svc; sleep .2;done      #访问测试 调度策略为轮询 1.0版本
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-xtz2n, ServerIP: 10.244.2.204!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-d8jm9, ServerIP: 10.244.1.218!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-xtz2n, ServerIP: 10.244.2.204!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-d8jm9, ServerIP: 10.244.1.218!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-xtz2n, ServerIP: 10.244.2.204!
  • 新增ReplicaSet 使用ikubernetes/demoapp:v1.1版本
[root@k8s-master PodControl]# cat replicaset.demo-v1.1.yaml 
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-demo-v1.1
spec:
  minReadySeconds: 3
  replicas: 1
  selector:
    matchLabels:
      app: demoapp
      release: stable
      version: v1.1
  template:
    metadata:
      labels:
        app: demoapp
        release: stable
        version: v1.1
        test: test22
    spec:
      containers:
      - name: demoapp
        image: ikubernetes/demoapp:v1.1
        ports:
        - name: http
          containerPort: 80

          
[root@k8s-master PodControl]# kubectl apply -f replicaset.demo-v1.1.yaml 
replicaset.apps/replicaset-demo-v1.1 created

[root@k8s-master PodControl]# kubectl get pod
NAME                         READY   STATUS    RESTARTS   AGE
pod-18865                    1/1     Running   0          26m
replicaset-demo-d8jm9        1/1     Running   1          12m
replicaset-demo-v1.1-dhmlq   1/1     Running   0          21s
replicaset-demo-xtz2n        1/1     Running   0          12m

  • 查看测试结果 SVC已经绑定到 1.1版本 新旧版本并存
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-dhmlq, ServerIP: 10.244.1.219!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-d8jm9, ServerIP: 10.244.1.218!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-xtz2n, ServerIP: 10.244.2.204!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-dhmlq, ServerIP: 10.244.1.219!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-d8jm9, ServerIP: 10.244.1.218!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-xtz2n, ServerIP: 10.244.2.204!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-dhmlq, ServerIP: 10.244.1.219!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-d8jm9, ServerIP: 10.244.1.218!
  • 修改老版本副本数
[root@k8s-master PodControl]# kubectl edit rs replicaset-demo
spec:
  minReadySeconds: 3
  replicas: 1
  selector:

[root@k8s-master PodControl]# kubectl get pod
NAME                         READY   STATUS    RESTARTS   AGE
pod-18865                    1/1     Running   0          30m
replicaset-demo-v1.1-dhmlq   1/1     Running   0          6m22s
replicaset-demo-xtz2n        1/1     Running   0          16m

  • 查看测试结果 新旧版本并存 访问量各占一半
root@pod-18865 # while true; do curl --connect-timeout 1 demoapp.default.svc; sleep .2;done
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-xtz2n, ServerIP: 10.244.2.204!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-dhmlq, ServerIP: 10.244.1.219!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-xtz2n, ServerIP: 10.244.2.204!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-dhmlq, ServerIP: 10.244.1.219!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-xtz2n, ServerIP: 10.244.2.204!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-dhmlq, ServerIP: 10.244.1.219!
  • 继续更新 新版本新增一个Pod 老版本删一个Pod
[root@k8s-master PodControl]# kubectl edit rs replicaset-demo-v1.1  #新版本副本数修改为2
replicaset.apps/replicaset-demo-v1.1 edited

[root@k8s-master PodControl]# kubectl edit rs replicaset-demo  #老版本副本数为0
replicaset.apps/replicaset-demo edited

[root@k8s-master PodControl]# kubectl get pod
NAME                         READY   STATUS    RESTARTS   AGE
pod-18865                    1/1     Running   0          34m
replicaset-demo-v1.1-bnck8   1/1     Running   0          80s
replicaset-demo-v1.1-dhmlq   1/1     Running   0          10m
  • 查看测试结果 更新版本完成
Kubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-bnck8, ServerIP: 10.244.3.50!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-dhmlq, ServerIP: 10.244.1.219!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-bnck8, ServerIP: 10.244.3.50!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: replicaset-demo-v1.1-dhmlq, ServerIP: 10.244.1.219!

示例3:蓝绿发布

envsubst使用环境变量替换文件内容 模板复用
  • 使用envsubst命令envsubst替换文件内容,默认kubernetes、YAML都是不支持变量的
[root@k8s-master PodControl]# cat replicaset-blue-gree.yaml 
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: rs-${DEPLOY} #为了使模板能复用 使用变量
spec:
  minReadySeconds: 3
  replicas: 2
  selector:
    matchLabels:
      app: demoapp
      ctr: rs-${DEPLOY}
      version: ${VERSION}
  template:
    metadata:
      labels:
        app: demoapp
        ctr: rs-${DEPLOY}
        version: ${VERSION}
    spec:
      containers:
      - name: demoapp
        image: ikubernetes/demoapp:${VERSION}
        ports:
        - name: http
          containerPort: 80

[root@k8s-master PodControl]# DEPLOY=blue VERSION=v1.0 envsubst < replicaset-blue-gree.yaml #替换变量
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: rs-blue #应用变量值
spec:
  minReadySeconds: 3
  replicas: 2
  selector:
    matchLabels:
      app: demoapp
      ctr: rs-blue
      version: v1.0
  template:
    metadata:
      labels:
        app: demoapp
        ctr: rs-blue
        version: v1.0
    spec:
      containers:
      - name: demoapp
        image: ikubernetes/demoapp:v1.0
        ports:
        - name: http
          containerPort: 80

[root@k8s-master PodControl]# DEPLOY=blue VERSION=v1.0 envsubst < replicaset-blue-gree.yaml |kubectl apply -f -   #创建SVC

[root@k8s-master PodControl]# cat replicaset-blue-gree.yaml 
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: rs-${DEPLOY} #为了使模板能复用 使用变量
spec:
  minReadySeconds: 3
  replicas: 2
  selector:
    matchLabels:
      app: demoapp
      ctr: rs-${DEPLOY}
      version: ${VERSION}
  template:
    metadata:
      labels:
        app: demoapp
        ctr: rs-${DEPLOY}
        version: ${VERSION}
    spec:
      containers:
      - name: demoapp
        image: ikubernetes/demoapp:${VERSION}
        ports:
        - name: http
          containerPort: 80

[root@k8s-master PodControl]# DEPLOY=blue VERSION=v1.0 envsubst < service-blue-green.yaml |kubectl apply -f -
service/demoapp-svc created

[root@k8s-master PodControl]# kubectl get svc
NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
demoapp       ClusterIP   10.97.26.1             80/TCP    113m
demoapp-svc   ClusterIP   10.99.170.77           80/TCP    20s
kubernetes    ClusterIP   10.96.0.1              443/TCP   11
  • 测试
root@pod-18865 # while true; do curl --connect-timeout 1 demoapp-svc.default.svc; sleep .2;done
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!   #可以看到全部来自rs-blue
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!
  • 新增rs用于更新发布
[root@k8s-master PodControl]# DEPLOY=green  VERSION=v1.1 envsubst < replicaset-blue-gree.yaml |kubectl apply -f -
replicaset.apps/rs-green created

[root@k8s-master PodControl]# kubectl get rs
NAME                   DESIRED   CURRENT   READY   AGE
replicaset-demo        0         0         0       92m
replicaset-demo-v1.1   2         2         2       81m
rs-blue                2         2         2       13m
rs-green               2         2         0       8s


[root@k8s-master PodControl]# kubectl get pod  #等Pod全部准备就绪
NAME                         READY   STATUS    RESTARTS   AGE
pod-18865                    1/1     Running   0          106m
replicaset-demo-v1.1-bnck8   1/1     Running   0          73m
replicaset-demo-v1.1-dhmlq   1/1     Running   0          82m
rs-blue-28lgc                1/1     Running   0          14m
rs-blue-gwnw7                1/1     Running   0          14m
rs-green-d4t66               1/1     Running   0          40s
rs-green-l75j7               1/1     Running   0          40s

[root@k8s-master PodControl]# DEPLOY=green  VERSION=v1.1 envsubst < service-blue-green.yaml |kubectl apply -f -
service/demoapp-svc configured
  • 查看测试结果
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!  #完成版本更新
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-d4t66, ServerIP: 10.244.1.222!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-d4t66, ServerIP: 10.244.1.222!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-d4t66, ServerIP: 10.244.1.222!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-d4t66, ServerIP: 10.244.1.222!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-d4t66, ServerIP: 10.244.1.222!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!
  • 修改变量 版本回退
[root@k8s-master PodControl]# DEPLOY=blue  VERSION=v1.0  envsubst < service-blue-green.yaml |kubectl apply -f -
service/demoapp-svc configured
#查看测试结果
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-d4t66, ServerIP: 10.244.1.222!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-d4t66, ServerIP: 10.244.1.222!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-d4t66, ServerIP: 10.244.1.222!
iKubernetes demoapp v1.1 !! ClientIP: 10.244.1.217, ServerName: rs-green-l75j7, ServerIP: 10.244.3.52!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!  #完成版本回退
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-28lgc, ServerIP: 10.244.1.220!
iKubernetes demoapp v1.0 !! ClientIP: 10.244.1.217, ServerName: rs-blue-gwnw7, ServerIP: 10.244.2.205!

你可能感兴趣的