关于Kubernetes-v1.23.6-资源调度-Deployment-创建与配置文件解析
Posted on 2023-09-17 20:32 520_1351 阅读(93) 评论(0) 编辑 收藏 举报Deployment的创建
可以按如下的方式创建一个 nginx 的deployment
可以看出,deployment 下面的 replicaset,而replicaset(即rs)下面就是pod了
[root@k8s-master deployments]# kubectl create deploy nginx-deploy --image=nginx:1.7.9 deployment.apps/nginx-deploy created [root@k8s-master deployments]# kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE nginx-deploy 1/1 1 1 12s [root@k8s-master deployments]# kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE nginx-deploy 1/1 1 1 26s [root@k8s-master deployments]# kubectl get replicaset NAME DESIRED CURRENT READY AGE nginx-deploy-78d8bf4fd7 1 1 1 49s [root@k8s-master deployments]# kubectl get rs NAME DESIRED CURRENT READY AGE nginx-deploy-78d8bf4fd7 1 1 1 54s [root@k8s-master deployments]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-deploy-78d8bf4fd7-s86tc 1/1 Running 0 61s [root@k8s-master deployments]#
可以通过名称,看出层次与所属的关系
获取一个deployment的配置信息
[root@k8s-master deployments]# kubectl get deploy nginx-deploy -o yaml apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "1" creationTimestamp: "2023-09-17T11:22:31Z" generation: 1 labels: app: nginx-deploy name: nginx-deploy namespace: default resourceVersion: "72556" uid: ed745961-c716-4913-963c-79a5b31a4675 spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: nginx-deploy strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: app: nginx-deploy spec: containers: - image: nginx:1.7.9 imagePullPolicy: IfNotPresent name: nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 status: availableReplicas: 1 conditions: - lastTransitionTime: "2023-09-17T11:22:33Z" lastUpdateTime: "2023-09-17T11:22:33Z" message: Deployment has minimum availability. reason: MinimumReplicasAvailable status: "True" type: Available - lastTransitionTime: "2023-09-17T11:22:31Z" lastUpdateTime: "2023-09-17T11:22:33Z" message: ReplicaSet "nginx-deploy-78d8bf4fd7" has successfully progressed. reason: NewReplicaSetAvailable status: "True" type: Progressing observedGeneration: 1 readyReplicas: 1 replicas: 1 updatedReplicas: 1 [root@k8s-master deployments]#
通过配置参考-编写自己的Deployment配置文件
只需要上面的status:之前的内容即可,创建nginx-deploy.yaml文件
删除一些不必要的,最终留下如下的信息即可
[root@k8s-master deployments]# cat nginx-deploy.yaml apiVersion: apps/v1 # deployment api 版本 kind: Deployment # 资源类型为 deployment metadata: # 元信息 labels: # 标签 app: nginx-deploy # 具体的key: value 配置形式 name: nginx-deploy # deployment 的名字 namespace: default # 所在的命名空间 spec: replicas: 1 # 指定副本数量,最少要有一个 revisionHistoryLimit: 10 # 进行滚动更新后,保留的历史版本数 selector: # 选择器,用于找到匹配的RS matchLabels: # 按照标签匹配 app: nginx-deploy # 匹配的标签 key: value strategy: # 更新策略 rollingUpdate: # 滚动更新配置 maxSurge: 25% # 进行滚动更新时,更新的个数最多可以超过期望副本数的个数/比例 maxUnavailable: 25% # 进行滚动更新时,最大不可用比例更新比例,表示在所有副本数中,最多可以有多少个不更新成功 type: RollingUpdate # 更新类型,采用滚动更新 template: # 描述我们的Pod该如何创建,Pod 模板 metadata: # Pod 的元信息 labels: # Pod 的标签 app: nginx-deploy # spec: # Pod 期望信息 containers: # Pod 的容器 - image: nginx:1.7.9 # 镜像 imagePullPolicy: IfNotPresent # 拉取策略 name: nginx # 容器名称 restartPolicy: Always # 重启策略 terminationGracePeriodSeconds: 30 # 删除操作最多宽限多长时间
这里我们只是创建出来,先暂时不使用,如果以后需要通过deployment配置文件进行相关资源的创建,可以使用命令:kubectl create -f nginx-deploy.yaml
扩展-删除Deployment-rs-pod资源
先进行查询
[root@k8s-master deployments]# kubectl get po,rs,deploy NAME READY STATUS RESTARTS AGE pod/nginx-deploy-78d8bf4fd7-s86tc 1/1 Running 0 51m NAME DESIRED CURRENT READY AGE replicaset.apps/nginx-deploy-78d8bf4fd7 1 1 1 51m NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/nginx-deploy 1/1 1 1 51m [root@k8s-master deployments]# kubectl get po,rs,deploy --show-labels NAME READY STATUS RESTARTS AGE LABELS pod/nginx-deploy-78d8bf4fd7-s86tc 1/1 Running 0 52m app=nginx-deploy,pod-template-hash=78d8bf4fd7 NAME DESIRED CURRENT READY AGE LABELS replicaset.apps/nginx-deploy-78d8bf4fd7 1 1 1 52m app=nginx-deploy,pod-template-hash=78d8bf4fd7 NAME READY UP-TO-DATE AVAILABLE AGE LABELS deployment.apps/nginx-deploy 1/1 1 1 52m app=nginx-deploy [root@k8s-master deployments]#
删除操作:kubectl delete deployment nginx-deploy
这样最上面创建的nginx-deploy这个deployment资源,以及相关的rs和pod资源就都被删除了
尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/17709740.html
作者:一名卑微的IT民工
出处:https://www.cnblogs.com/5201351
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
由于博主的水平不高,文章没有高度、深度和广度,只是凑字数,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个卑微的IT民工!