iT邦幫忙

2022 iThome 鐵人賽

DAY 5
0

Deployments:它的角色比較像是幫你管理Pod,在yaml中指定副本數(replicas)後會維持Pod剛好等於指定數量,也就是說可以用來達到自我修復的功能。除此之外它還有滾動更新的功能(之後再提),可以更換Pod裡容器的image版本。

Deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-demo
  labels:
    app: ubuntu
spec:
  replicas: 2
  selector:
    matchLabels:
      app: ubuntu
  template:
    metadata:
      labels:
        app: ubuntu
    spec:
      containers:
      - name: ubuntu
        image: ubuntu:20.04
        args: [bash, -c, 'for ((i = 0; ; i++)); do echo "$i: $(date)"; sleep 100; done']

部屬Deployment

root@master:/# kubectl apply -f deployment.yaml 
deployment.apps/deployment-demo created

查看Deployment

root@master:/# kubectl get deployment
NAME              READY   UP-TO-DATE   AVAILABLE   AGE
deployment-demo   2/2     2            2           20s

查看pod

root@master:/# kubectl get pod
NAME                              READY   STATUS    RESTARTS   AGE
deployment-demo-68d5b9f46-4d4z9   1/1     Running   0          4s
deployment-demo-68d5b9f46-zthrv   1/1     Running   0          4s

自我修復

先刪除deployment-demo-68d5b9f46-4d4z9,再查看pod

root@master:/# kubectl delete pod deployment-demo-68d5b9f46-4d4z9
pod "deployment-demo-68d5b9f46-4d4z9" deleted
root@master:/# kubectl get pod
NAME                              READY   STATUS    RESTARTS   AGE
deployment-demo-68d5b9f46-fs2lf   1/1     Running   0          78s
deployment-demo-68d5b9f46-zthrv   1/1     Running   0          104m

上一篇
Day4-Pod&Service
下一篇
Day6-DaemonSet
系列文
技能亂點的無名打工仔技能記錄30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言