9.Pod控制器概念和基本操作2

利用一个简单的例子来启动一个deployment的Pod控制器 9.Pod控制器概念和基本操作2
[root@master song]# cat deploy.yml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deploy
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
      release: canary
  template:
    metadata:
      labels:
        app: myapp
        release: canary
    spec:
      containers:
      - name: myapp
        image: ikubernetes/myapp:v1
Pod.yml

 启动控制器

kubectl create --save-config  -f deploy.yml
[root@master song]# !952
kubectl get pod -l app=myapp
NAME                            READY   STATUS    RESTARTS   AGE
myapp-deploy-7769f49474-lq7dw   1/1     Running   0          14m   
myapp-deploy-7769f49474-v4nj4   1/1     Running   0          14m

查看deployment和rs之间的命名关系

[root@master song]# kubectl get deployments.
NAME           READY   UP-TO-DATE   AVAILABLE   AGE
myapp-deploy   2/2     2            2           15m
nginx-test     2/2     2            2           6d21h
tomcat-test    2/2     2            2           6d18h
[root@master song]# kubectl get rs
NAME                      DESIRED   CURRENT   READY   AGE
myapp-deploy-7769f49474   2         2         2       15m           rs控制器的名字为deployment的名称+随机串
nginx-test-8bbbdc7d5      2         2         2       6d21h
nginx-test-8f5f46d94      0         0         0       6d20h
tomcat-test-76789745c5    2         2         2       6d18h

编辑配置文件 将 replicas改为3

使用  kubectl  get pods  -l app=myapp  -w

^C[root@master ~]# kubectl get pods -l app=myapp -w
NAME                            READY   STATUS    RESTARTS   AGE
myapp-deploy-84d9546645-l6gvz   1/1     Running   0          6m3s
myapp-deploy-84d9546645-lmn8n   1/1     Running   0          6m3s
pod-demo                        2/2     Running   0          2d3h
myapp-deploy-84d9546645-tjhtr   0/1   Pending   0     0s
myapp-deploy-84d9546645-tjhtr   0/1   Pending   0     0s
myapp-deploy-84d9546645-tjhtr   0/1   ContainerCreating   0     0s
myapp-deploy-84d9546645-tjhtr   1/1   Running   0     2s

在将配置文件中 副本数一值改为5,进行版本升级操作

是控制器配置生效的集中操作  apply直接更改配置文件   edit 编辑动态配置   path 命令行动态的以json形式进行资源更改

kubectl patch deployments myapp-deploy  -p '{"spec":{"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":0}}}}'   字母不能错,错了不提示

查看最新描述中有关rollingUpdate 的部分操作

Selector:               app=myapp,release=canary
Replicas:               5 desired | 5 updated | 5 total | 5 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  0 max unavailable, 1 max surge

进行版本更新,并在途中执行pause命令来进行服务暂停

[root@master song]# kubectl set image deployment myapp-deploy myapp=ikubernetes/myapp:v2 && kubectl rollout pause deployment myapp-deploy 
deployment.extensions/myapp-deploy image updated
deployment.extensions/myapp-deploy paused

查看状态
[root@master ~]# kubectl get pods -l app=myapp -w
NAME                            READY   STATUS    RESTARTS   AGE
myapp-deploy-7769f49474-8zxl2   1/1     Running   0          13m
myapp-deploy-7769f49474-jsj6l   1/1     Running   0          20m
myapp-deploy-7769f49474-nkr5g   1/1     Running   0          13m
myapp-deploy-7769f49474-vc6dg   1/1     Running   0          20m
myapp-deploy-7769f49474-wg2cx   1/1     Running   0          20m
pod-demo                        2/2     Running   0          2d4h
myapp-deploy-84d9546645-v55vd   0/1   Pending   0     0s
myapp-deploy-84d9546645-v55vd   0/1   Pending   0     0s
myapp-deploy-84d9546645-v55vd   0/1   ContainerCreating   0     0s
myapp-deploy-84d9546645-v55vd   1/1   Running   0     1s

describe 来查看资源状态,5个副本中多出来一个就是我们的新启动的这个

Selector:               app=myapp,release=canary
Replicas:               5 desired | 1 updated | 6 total | 6 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  0 max unavailable, 1 max surge
Pod Template:

 

Daemonset 控制器

 

上一篇:全局变量


下一篇:k8s-service