[case study] Deployment & Service & Containerd

Preparation

Containerd Image preparation

制作Containerd镜像

Deployment with rolling update preparation

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-web-service
  labels:
    app: proj
spec:
  # RelicaSet - template - pod description
  # RelicaSet - replicas - pod number
  # RelicaSet - selector - pod finder
  replicas: 3
  selector:              # match the pod label @1
    matchLabels:
      app: proj
  template:
    metadata:
      labels:            # pod label @1
        app: proj
    spec:
      containers:
        - name: ngx-container
          image: docker.io/library/my-web-service:v1
  # Rolling Update - minReadySeconds - pod will provide service after waiting 30s.
  # Rolling Update - maxSurge        - number or percentage of additional pods during rolling update.
  # Rolling Update - maxUnavailable  - number or percentage of pod that won't provide service during rolling update.
  minReadySeconds: 30
  strategy:
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1

Service preparation

apiVersion: v1
kind: Service
metadata:
  name: my-web-service
spec:
  type: NodePort
  ports:
    - targetPort: 8080
      port: 8080
      nodePort: 30008
  selector:
    app: proj

部署第一个镜像

kubectl apply -f my-web-service-deployment.yaml
kubectl apply -f my-web-service-service.yaml

kubectl get pod -A
kubectl get service -A
kubectl get deployment -A

验证第一次发布

kubectl rollout history deployment/my-web-service
kubectl rollout status deployment/my-web-service

部署第二个版本

Containerd Image preparation

准备第二个容器的镜像v2 制作Containerd镜像

修改deployment文件中的镜像为v2

          image: docker.io/library/my-web-service:v2

部署

# 滚动更新为v2的镜像
kubectl apply -f my-web-service-deployment.yaml
# 等待发布完成
kubectl rollout status deployment/my-web-service
# 查看发布历史
kubectl rollout history deployment/my-web-service
# UI验证 http://ip:30008/v1/get ==> 显示v2
# 回滚到上一个版本,也就是v1
kubectl rollout undo deployment/my-web-service
# 回滚到指定版本1, 也就是v1
kubectl rollout undo deployment/my-web-service --to-revision=1
# 等待发布完成
kubectl rollout status deployment/my-web-service
# UI验证 http://ip:30008/v1/get ==> 显示v1
posted @ 2022-07-20 15:10  608088  阅读(28)  评论(0编辑  收藏  举报