Pod 控制器资源通过持续性地监控集群中运行着的 Pod 资源对象来确保受其管控的资源严格符合用户期望的状态,例如资源副本的数量要精确符合期望等。通常,一个Pod 控制器资源至少应该包含三个基本的组成部分。
 
标签选择器:匹配并关联 Pod 资源对象,并据此完成受其管控的 Pod 资源计数。
期望的副本数:期望在集群中精确运行着的 Pod 资源的对象数量。
Pod 模板:用于新建 Pod 资源对象的 Pod 模板资源。
 
 
apiVersion: apps/v1 
kind: Deployment 
metadata: 
  name: myapp-deploy 
spec: 
  replicas: 3 
  selector: 
    matchLabels: 
      app: myapp 
  template: 
    metadata: 
      labels: 
        app: myapp 
    spec: 
      containers: 
      - name: myapp 
        image: ikubernetes/myapp:v1 
        ports: 
        - containerPort: 80 
          name: http 

# kubectl apply -f myapp-deploy.yaml --record
# kubectl get deployments myapp-deploy
# kubectl get pods -l app=myapp
# kubectl describe deployments myapp-deploy
# kubectl describe pod myapp-deploy-79859f456c 

#patch更新
# kubectl patch deployments myapp-deploy  -p '{"spec": {"strategy":{"rollingUpdate": {"maxSurge": 1, "maxUnavailable": 0}}}}'

# 回滚
# kubectl rollout undo deployments myapp-deploy
# kubectl rollout undo deployments myapp-deploy --to-revision=2

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐