kubectl run nginx-deployment --image=nginx:1.7.9 --replicas=2
deployment.apps/nginx-deployment created
部署了2个副本的 nginx-deployment,容器的 image 为 nginx:1.7.9。
查看 deployment:
kubectl get deployment nginx-deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 6m22s
显示2个副本都正常运行,下面看一下详细信息:
kubectl describe deployment nginx-deployment
返回信息:
Name: nginx-deployment
Namespace: default
CreationTimestamp: Wed, 12 Dec 2018 06:46:42 +0000
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-578fb949d8 (2/2 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 7m22s deployment-controller Scaled up replica set nginx-deployment-578fb949d8 to 2
内容比较易懂,其中 Conditions
下面有一条信息 NewReplicaSet: nginx-deployment-578fb949d8 (2/2 replicas created)
,说明创建了 ReplicaSet,名称是 nginx-deployment-578fb949d8
,下面就看一下 ReplicaSet:
kubectl describe replicaset nginx-deployment-578fb949d8
返回信息:
Name: nginx-deployment-578fb949d8
Namespace: default
Selector: pod-template-hash=578fb949d8,run=nginx-deployment
Labels: pod-template-hash=578fb949d8
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=578fb949d8
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 17m replicaset-controller Created pod: nginx-deployment-578fb949d8-5wpfx
Normal SuccessfulCreate 17m replicaset-controller Created pod: nginx-deployment-578fb949d8-jxxbr
其中的 Controlled By
说明是由 Deployment/nginx-deployment
创建的,最下面的 Events
是日志,表明创建了2个 pod,看一下 pod 列表:
kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-deployment-578fb949d8-5wpfx 1/1 Running 0 22m
nginx-deployment-578fb949d8-jxxbr 1/1 Running 0 22m
下面再看 pod 的详细信息:
kubectl describe pod nginx-deployment-578fb949d8-5wpfx
返回信息:
Name: nginx-deployment-578fb949d8-5wpfx
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: microk8s/10.0.2.15
Start Time: Wed, 12 Dec 2018 06:46:42 +0000
Labels: pod-template-hash=578fb949d8
run=nginx-deployment
Annotations: <none>
Status: Running
IP: 10.1.1.106
Controlled By: ReplicaSet/nginx-deployment-578fb949d8
Containers:
nginx-deployment:
Container ID: docker://e9431c0e17ee5c2171c2b1d34d39f02f65073120fdcbae109fd75cb9fab6143c
Image: nginx:1.7.9
Image ID: docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451
Port: <none>
Host Port: <none>
State: Running
Started: Wed, 12 Dec 2018 06:47:08 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-n44dv (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-n44dv:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-n44dv
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 24m default-scheduler Successfully assigned default/nginx-deployment-578fb949d8-5wpfx to microk8s
Normal Pulling 24m kubelet, microk8s pulling image "nginx:1.7.9"
Normal Pulled 23m kubelet, microk8s Successfully pulled image "nginx:1.7.9"
Normal Created 23m kubelet, microk8s Created container
Normal Started 23m kubelet, microk8s Started container
其中的 Controlled By
说明是 ReplicaSet/nginx-deployment-578fb949d8
创建的,Events
记录了 pod 的启动过程,如果出现问题,可以在这里查看原因。
总结一下启动过程:
- 用户通过 kubectl 创建 deployment(nginx-deployment)
- deployment(nginx-deployment)创建了 replicaset(nginx-deployment-578fb949d8)
- replicaset(nginx-deployment-578fb949d8)创建了2个 pod (nginx-deployment-578fb949d8-5wpfx、nginx-deployment-578fb949d8-jxxbr)
从中可以看到对象的命名方式:父对象名字 + 随机字符串
网友评论