内容简介:我们接着前面的文章说,如果不清楚的请查看之前的博文:前面我们已经了解到,Kubernetes 通过各种 Controller 来管理 Pod 的生命周期。为了满足不同业务场景,Kubernetes 开发了 Deployment、ReplicaSet、DaemonSet、StatefuleSet、Job 等多种 Controller。我们首先学习最常用的 Deployment。先从例子开始,运行一个 Deployment:
一、Deployment
我们接着前面的文章说,如果不清楚的请查看之前的博文: http://blog.51cto.com/wzlinux/2322616
前面我们已经了解到,Kubernetes 通过各种 Controller 来管理 Pod 的生命周期。为了满足不同业务场景,Kubernetes 开发了 Deployment、ReplicaSet、DaemonSet、StatefuleSet、Job 等多种 Controller。我们首先学习最常用的 Deployment。
1、运行 Deployment
先从例子开始,运行一个 Deployment:
kubectl run nginx-deployment --image=nginx:1.7.9 --replicas=2
上面的命令将部署包含两个副本的 Deployment nginx-deployment
,容器的 image 为 nginx:1.7.9
。
2、查看 Deployment(deploy)
查看刚刚创建的 deployment,其可以简写为deploy。
[root@master ~]# kubectl get deploy NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx-deployment 2 2 2 2 4m56s
使用命令 kubectl describe deploy
查看内部内容。
kubectl describe deploy nginx-deployment
Name: nginx-deployment Namespace: default CreationTimestamp: Thu, 29 Nov 2018 17:47:16 +0800 Labels: run=nginx-deployment Annotations: deployment.kubernetes.io/revision: 1 Selector: run=nginx-deployment Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 25% max unavailable, 25% max surge Pod Template: Labels: run=nginx-deployment Containers: nginx-deployment: Image: nginx:1.7.9 Port: <none> Host Port: <none> Environment: <none> Mounts: <none> Volumes: <none> Conditions: Type Status Reason ---- ------ ------ Available True MinimumReplicasAvailable Progressing True NewReplicaSetAvailable OldReplicaSets: <none> NewReplicaSet: nginx-deployment-5fd98dbf5f (2/2 replicas created) Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal ScalingReplicaSet 6m11s deployment-controller Scaled up replica set nginx-deployment-5fd98dbf5f to 2
展示的内容大部分都是描述信息,我们看最后一行,这里告诉我们创建了一个 ReplicaSet nginx-deployment-5fd98dbf5f
,Events 是 Deployment 的日志,记录了 ReplicaSet 的启动过程。
通过上面的分析,也验证了 Deployment 通过 ReplicaSet 来管理 Pod 的事实。
3、查看 ReplicaSet(rs)
查看我们有哪些 rs。
[root@master ~]# kubectl get rs NAME DESIRED CURRENT READY AGE nginx-deployment-5fd98dbf5f 2 2 2 12m
使用命令 kubectl describe rs
查看其详细信息。
kubectl describe rs nginx-deployment-5fd98dbf5f
Name: nginx-deployment-5fd98dbf5f Namespace: default Selector: pod-template-hash=5fd98dbf5f,run=nginx-deployment Labels: pod-template-hash=5fd98dbf5f run=nginx-deployment Annotations: deployment.kubernetes.io/desired-replicas: 2 deployment.kubernetes.io/max-replicas: 3 deployment.kubernetes.io/revision: 1 Controlled By: Deployment/nginx-deployment Replicas: 2 current / 2 desired Pods Status: 2 Running / 0 Waiting / 0 Succeeded / 0 Failed Pod Template: Labels: pod-template-hash=5fd98dbf5f run=nginx-deployment Containers: nginx-deployment: Image: nginx:1.7.9 Port: <none> Host Port: <none> Environment: <none> Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 13m replicaset-controller Created pod: nginx-deployment-5fd98dbf5f-8g7nm Normal SuccessfulCreate 13m replicaset-controller Created pod: nginx-deployment-5fd98dbf5f-58c4z
我们可以看到 Controlled By: Deployment/nginx-deployment
,说明此 ReplicaSet 由 Deployment nginx-deployment
。
在 Events
记录了两个副本 Pod 的创建,那我们查看一下 Pod。
4、查看 Pod
查看目前的 Pod。
[root@master ~]# kubectl get pods NAME READY STATUS RESTARTS AGE nginx-deployment-5fd98dbf5f-58c4z 1/1 Running 0 19m nginx-deployment-5fd98dbf5f-8g7nm 1/1 Running 0 19m
随便选择一个 Pod,查看其详细信息。
kubectl describe pod nginx-deployment-5fd98dbf5f-58c4z
Name: nginx-deployment-5fd98dbf5f-58c4z Namespace: default Priority: 0 PriorityClassName: <none> Node: node02.wzlinux.com/172.18.8.202 Start Time: Thu, 29 Nov 2018 17:47:16 +0800 Labels: pod-template-hash=5fd98dbf5f run=nginx-deployment Annotations: <none> Status: Running IP: 10.244.2.3 Controlled By: ReplicaSet/nginx-deployment-5fd98dbf5f Containers: nginx-deployment: Container ID: docker://69fa73ed16d634627b69b8968915d9a5704f159206ac0d3b2f1179fa99acd56f Image: nginx:1.7.9 Image ID: docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451 Port: <none> Host Port: <none> State: Running Started: Thu, 29 Nov 2018 17:47:28 +0800 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-sm664 (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: default-token-sm664: Type: Secret (a volume populated by a Secret) SecretName: default-token-sm664 Optional: false QoS Class: BestEffort Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s node.kubernetes.io/unreachable:NoExecute for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 20m default-scheduler Successfully assigned default/nginx-deployment-5fd98dbf5f-58c4z to node02.wzlinux.com Normal Pulling 20m kubelet, node02.wzlinux.com pulling image "nginx:1.7.9" Normal Pulled 20m kubelet, node02.wzlinux.com Successfully pulled image "nginx:1.7.9" Normal Created 20m kubelet, node02.wzlinux.com Created container Normal Started 20m kubelet, node02.wzlinux.com Started container
我们可以看到 Controlled By: ReplicaSet/nginx-deployment-5fd98dbf5f
,说明此 Pod 是由 ReplicaSet nginx-deployment-5fd98dbf5f
创建的。
Events
记录了 Pod 的启动过程。
5、总结
- 用户通过 kubectl 创建 Deployment。
- Deployment 创建 ReplicaSet。
- ReplicaSet 创建 Pod。
从上图也可以看出,对象的命名方式是:子对象的名字 = 父对象名字 + 随机字符串或数字。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- ASP.NET Core模块化前后端分离快速开发框架介绍之3、数据访问模块介绍
- 简编漫画介绍WebAssembly
- CGroup 介绍
- CGroup 介绍
- vue初步介绍
- Microbit MicroPython 介绍
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。