k8s基础之三 无状态服务Deployment
deployment
用于部署无状态的服务,最常用的控制器,一般用于管理维护企业内部无状态的微服务,比如configserver、zuul、springboot。他可以管理多个副本的pod实现无缝迁移、自动扩容缩容。自动灾难恢复、一键回滚等功能
启动一个Deployment
命令创建:
kubectl create deployment --image=nginx:1.15.2
从文件创建:
[root@master01 ~]# kubectl apply -f web.yaml [root@master01 ~]# cat web.yaml apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "1" creationTimestamp: "2021-12-05T11:30:09Z" generation: 3 labels: app: web name: web namespace: default spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: web #这两个地方名字要一样 strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: app: web #这两个地方名字要一样 spec: containers: - image: nginx:1.15.2 imagePullPolicy: IfNotPresent name: nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30
状态解析:
kubectl get deploy -owide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR nginx 1/1 1 1 2d18h nginx nginx app=nginx web 1/1 1 1 37m nginx nginx:1.15.2 app=web You have new mail in /var/spool/mail/root NAME deployment名称 READY pod的个数,已经准备/总数 UP-TO-DATE 已经达到期望状态的被更新副本数(已经完全就绪的副本数,达到预期状态) AVAILABLE 已经可以用的副本数 AGE 已经允许了多久 CONTAINERS 容器名称 IMAGES 容器镜像名称 SELECTOR 标签
可以执行“kubectl get deploy web -o yaml > web.yaml” 导出一个文件,通过文件管理,也可以通过命令"kubectl edit deploy web" 这样的命令方式管理