Pod控制器
- ReplicationController:后续会被Replicaset取代
- Replicaset:用作pod 创建、删除和更新,ReplicaSet能确保运行指定数量的pod ,通过label selector来确定pod数量是否满足用户指定的副本数量。
- Deployment:将 Pod 和ReplicaSet 的实际状态改变到用户的目标状态。支持扩容、回滚、更新等功能;管理无状态应用最好的控制器;守护进程类
- Daemonset:确保每个节点上运行一个Pod副本。无状态服务;守护进程类
- Job: 执行一次性运行任务。不需要持续运行
- Cronjob: 周期性运行任务。不需要持续运行
- StatefulSet: 管理有状态应用,每一个应用都被单独管理。管理比较麻烦
Replicaset:
root@k8s-master:/home/ubuntu/manifests/basic# cat rs-demo.yaml
apiVersion: apps/v1 kind: ReplicaSet metadata: name: my-rs namespace: develop spec: replicas: 2 selector: matchLabels: app: my-app template: # template下是创建Pod所需的资源,label需要包含rs自己的label metadata: name: myrs-pod labels: app: my-app release: v0.1 env: test spec: containers: - name: rs-nginx image: nginx ports: - name: http containerPort: 80 protocol: TCP
♥♥♥ kubectl edit resouce resouce_name ♥♥♥
kubectl edit rs my-rs -n develop #直接编辑develop下的my-rs的配置文件
ƒ deloy 滚动更新
Deployment:
root@k8s-master:/home/ubuntu/manifests/basic# cat deploy-demo.yaml apiVersion: apps/v1 kind: Deployment metadata: name: deploy-demo namespace: develop spec: replicas: 2 selector: matchLabels: app: deploy release: v0.2 template: # template内容为创建pod所需的资源,labels需要包含deploy selector的标签, deploy会自动调用ReplicaSet来创建Pod metadata: labels: app: deploy release: v0.2 spec: containers: - name: deploy-ngx image: nginx ports: - name: http containerPort: 80
默认更新策略: RollingUpdate
DaemonSet :
root@k8s-master:/home/ubuntu/manifests/basic# cat daemonset-demo.yaml apiVersion: apps/v1 kind: DaemonSet metadata: name: ds-demo namespace: develop spec: selector: matchLabels: app: ds release: v0.3 template: metadata: labels: app: ds release: v0.3 spec: containers: - name: ds-filebeat image: filebeat env: - name: REDIS_HOST value: redis.default.svc.cluster.local - name: REDIS_LOG_LEVEL value: info