关于kubernetes:02kubernetes笔记-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 <integer>  #Pod就绪后多少秒内任一容器无crash方可视为“就绪”
  replicas <integer> #冀望的Pod正本数,默认为1
  selectorl:  #标签选择器,必须匹配template字段中Pod模板中的标签;
    matchExpressions_<[ ]Object> #标签选择器表达式列表,多个列表项之间为“与"关系 
    matchLabels <map[string]string> #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   <none>           <none>
replicaset-demo-b4hx9         1/1     Running   0          34m   10.244.1.210   k8s-node1   <none>           <none>
replicaset-demo-zb7m5         1/1     Running   1          34m   10.244.2.203   k8s-node2   <none>           <none>

#查看形容信息
[root@k8s-master PodControl]# kubectl describe replicasets/replicaset-demo
Name:         replicaset-demo
Namespace:    default
Selector:     app=demoapp,release=stable,version=v1.0
Labels:       <none>
Annotations:  <none>
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:  <none>
    Mounts:       <none>
  Volumes:        <none>
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   <none>           <none>
replicaset-demo-b4hx9         1/1     Running   0          34m   10.244.1.210   k8s-node1   <none>           <none>
replicaset-demo-zb7m5         1/1     Running   1          34m   10.244.2.203   k8s-node2   <none>           <none>

[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   <none>           <none>
replicaset-demo-686fl         0/1     Running   1          2m28s   10.244.1.212   k8s-node1   <none>           <none>
replicaset-demo-k4pq9         0/1     Running   0          2m28s   10.244.3.49    k8s-node3   <none>           <none>

[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     <none>        80/TCP    113m
demoapp-svc   ClusterIP   10.99.170.77   <none>        80/TCP    20s
kubernetes    ClusterIP   10.96.0.1      <none>        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!

【腾讯云】轻量 2核2G4M,首年65元

阿里云限时活动-云数据库 RDS MySQL  1核2G配置 1.88/月 速抢

本文由乐趣区整理发布,转载请注明出处,谢谢。

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据