码迷,mamicode.com
首页 > 其他好文 > 详细

Pod控制器

时间:2018-11-06 22:23:39      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:yam   ons   声明   守护进程   周期性   image   date   max   template   

一、Pod控制器简介

  • ReplicationController(目前已废弃)
  • ReplicaSet(不建议直接使用):用户期望的Pod副本数,标签选择器以便选择自己管理控制的副本,Pod资源模板来完成Pod的新建,主要管理无状态的Pod资源副本
  • Deployment:通过控制ReplicaSet之上来工作,支持滚动更新,回滚,基于声明式创建,在Pod运行中可动态修改Pod参数
  • DaemonSet:以守护进程的方式来控制Pod,在集群中每个节点运行一个Pod副本
  • Job:执行一次性的作业Pod
  • Cronjob:执行周期性的作业Pod
  • StatefulSet:管理有状态Pod,每个Pod都要有可能是有状态、数据的

二、ReplicaSet

  • 获取帮助
# kubectl explain ReplicaSet
# kubectl explain ReplicaSet.spec
# kubectl explain ReplicaSet.spec.template
# kubectl explain ReplicaSet.spec.template.spec
  • 简单定义
manifests]# vim rs-demo.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
      release: canary
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        release: canary
        environment: qa
    spec:
      containers:
      - name: myapp-container
        image: dongfeimg/myapp:v1
        ports:
        - name: http
          containerPort: 80
# kubectl get rs
  • 手动扩容/缩容
# kubectl edit rs myapp
spec:
  replicas: 5  #可动态修改Pod副本
  • 手动升级image
# kubectl edit rs myapp
    spec:
      containers:
      - image: dongfeimg/myapp:v2
# kubectl get rs -o wide

注意:只有重建的Pod才是新版本的image

三、Deployment

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: dongfeimg/myapp:v1
        ports:
        - name: http
          containerPort: 80
# kubectl apply -f Deployment-damo.yaml
# kubectl get deploy
# kubectl get rs
# kubectl get pods
# kubectl describe deploy myapp-deploy
  • 查看历史记录
# kubectl rollout history deployment myapp-deploy
  • 监控查看pod状态
# kubectl get pods -l app=myapp -w
  • 通过打补丁的方式扩容
# kubectl patch deployment myapp-deploy -p '{"spec":{"relicas":5}}'
  • 滚动更新指定超出一个pod
# kubectl patch deployment myapp-deploy -p '{"spec":{"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":0}}}}'
  • 更新image版本(金丝雀发布)
# kubectl set image deployment myapp-deploy myapp=dongfeimg/myapp:v2 && kubectl rollout pause deployment myapp-deploy  #丢出一只金丝雀
# kubectl rollout status deployment myapp-deploy
# kubectl get pods -l app=myapp -w
# kubectl rollout resume deployment myapp-deploy  #所有的都开始更新
  • 回滚
# kubectl rollout history deployment myapp-deploy  #查看历史版本
# kubectl rollout undo deployment myapp-deploy --to-revision=1  #回滚到第一版

四、DaemonSet

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: filebeat-ds
  namespace: default
spec:
  selector:
    matchLabels:
      app: filebeat
      release: stable
  template:
    metadata:
      labels:
        app: filebeat
        release: stable
    spec:
      containers:
      - name: filebeat
        image: dongfeimg/filebeat:5.6.5-alpine
        env:
        - name: REDIS_HOST
          value: redis.default.svc.cluster.local
        - name: REDIS_LOG_LEVEL
          value: info

filebeat + redis

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
      role: logstor
  template:
    metadata:
      labels:
        app: redis
        role: logstor
    spec:
      containers:
      - name: redis
        image: redis:4.0-alpine
        ports:
        - name: redis
          containerPort: 6379
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: filebeat-ds
  namespace: default
spec:
  selector:
    matchLabels:
      app: filebeat
      release: stable
  template:
    metadata:
      labels:
        app: filebeat
        release: stable
    spec:
      containers:
      - name: filebeat
        image: dongfeimg/filebeat:5.6.5-alpine
        env:
        - name: REDIS_HOST
          value: redis.default.svc.cluster.local
        - name: REDIS_LOG_LEVEL
          value: info
  • 更新image版本
# kubectl set image daemonsets filebeat-ds filebeat=ikubernetes/filebeat:5.6.6-alpine

Pod控制器

标签:yam   ons   声明   守护进程   周期性   image   date   max   template   

原文地址:https://www.cnblogs.com/L-dongf/p/9918067.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!