k8s控制器

Kubernetes的控制器类型
◼ 打包于Controller Manager中内置提供的控制器,例如Service Controller、Deployment Controller等
◆基础型、核心型控制器
◆打包运行于kube-controller-manager中
◼ 插件或第三方应用的专用控制器,例如Ingress插件ingress-nginx的Controller,网络插件Project Calico的
Controller等
◆高级控制器,通常需要借助于基础型控制器完成其功能
◆以Pod形式托管运行于Kubernetes之上,而且这些Pod很可能会由内置的控制器所控制

以编排Pod化运行的应用为核心的控制器,通常被统称为工作负载型控制器
◼ 无状态应用编排:ReplicaSet、Deployment
◼ 有状态应用编排:StatefulSet、第三方专用的Operator
◼ 系统级应用:DaemonSet
◼ 作业类应用:Job和CronJob

replicas

不支持滚动更新,

1.0版本

cat  replicaset-demo.yaml 
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-demo
spec:
  minReadySeconds: 3
  replicas: 3
  selector:
    matchLabels:
      app: demoapp
      release: stable
      version: v1.0
  template:
    metadata:
      labels:
        app: demoapp
        release: stable
        version: v1.0
    spec:
      containers:
      - name: demoapp
        image: ikubernetes/demoapp:v1.0
        ports:
        - name: http
          containerPort: 80
        livenessProbe:
          httpGet:
            path: '/livez'
            port: 80
          initialDelaySeconds: 15
        readinessProbe:
          httpGet:
            path: '/readyz'
            port: 80
          initialDelaySeconds: 15

1.1版本

cat replicaset-demo-v1.1.yaml 
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-demo-v1.1
spec:
  minReadySeconds: 3
  replicas: 2
  selector:
    matchLabels:
      app: demoapp
      release: stable
      version: v1.1
  template:
    metadata:
      labels:
        app: demoapp
        release: stable
        version: v1.1
    spec:
      containers:
      - name: demoapp
        image: ikubernetes/demoapp:v1.1
        ports:
        - name: http
          containerPort: 80
        livenessProbe:
          httpGet:
            path: '/livez'
            port: 80
          initialDelaySeconds: 5
        readinessProbe:
          httpGet:
            path: '/readyz'
            port: 80
          initialDelaySeconds: 15

通过修改svc中selector中version实现版本更新

cat  service-blue-green.yaml
# VERSION: demoapp version
# DEPLOY: blue OR green
# Maintainer: MageEdu 
---
apiVersion: v1
kind: Service
metadata:
  name: demoapp-svc
  namespace: default
spec:
  type: ClusterIP
  selector:
    app: demoapp
      #ctr: rs-${DEPLOY}
    version: v1.1
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80

蓝绿部署
新版本部署好,直接切换到新版本

金雀丝部署
新版本和旧版本同时并存,最后全部替换为新版本
旧版本5个 新版本0
旧版本4个 新版本1个

deployment

支持滚动更新

自己修改deployment镜像,可以实现滚动更新

root@server01:~/k8s/Kubernetes_Advanced_Practical_2rd/chapter8# kubectl rollout  status  deployment  deployment-demo 
deployment "deployment-demo" successfully rolled out
root@server01:~/k8s/Kubernetes_Advanced_Practical_2rd/chapter8# kubectl rollout  history   deployment  deployment-demo 
deployment.apps/deployment-demo 
REVISION  CHANGE-CAUSE
1         <none>
2         <none>

你可能感兴趣的:(kubernetes,容器,云原生)