k8s(Kubernetes)中Pod,Deployment,ReplicaSet,Service之间关系分析
看完k8s文档,好多概念似乎明白了,又似乎不明白,多个概念之间的关系也很混乱,不是很明白,不要紧,接下来,好好分析一下。结论您有可能在急着找答案搜到我这篇文章,不费话,结论就在开头,请看下图。deploy控制RS,RS控制Pod,这一整套,向外提供稳定可靠的Service。分析以下是分析的过程首先,我们先从最小的调度单位pod开始。我的k8s集群中目前有一个pod,它...
·
看完k8s文档,好多概念似乎明白了,又似乎不明白,多个概念之间的关系也很混乱,不是很明白,不要紧,接下来,好好分析一下。
结论
您有可能在急着找答案搜到我这篇文章,不费话,结论就在开头,请看下图。
deploy控制RS,RS控制Pod,这一整套,向外提供稳定可靠的Service。
分析
以下是分析的过程
- 首先,我们先从最小的调度单位pod开始。
我的k8s集群中目前有一个pod,它的name为mq-svc-5b96bf78d9-brpjw
[root@VM_0_17_centos ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
mq-svc-5b96bf78d9-brpjw 1/1 Running 0 51m
来看一下它的详情
[root@VM_0_17_centos ~]# kubectl describe pod mq-svc-5b96bf78d9-brpjw
Name: mq-svc-5b96bf78d9-brpjw
Namespace: default
Node: 10.0.0.17/10.0.0.17
Start Time: Fri, 17 Aug 2018 17:24:44 +0800
Labels: pod-template-hash=1652693485
qcloud-app=mq-svc
Annotations: <none>
Status: Running
IP: 172.16.0.39
Controlled By: ReplicaSet/mq-svc-5b96bf78d9
Containers:
queue-mq:
Container ID: docker://700cdc55c111a413faaa8cabb8680009d2663701ccbe84b8a50ea6e6fe1d538c
Image: rabbitmq:management
Image ID: docker-pullable://rabbitmq@sha256:0b36ea1a8df9e53228aaeee277680de2cc97c7d675bc2d5dbe1cc9e3836a9d9f
Port: <none>
Host Port: <none>
State: Running
Started: Fri, 17 Aug 2018 17:24:49 +0800
Ready: True
Restart Count: 0
Limits:
cpu: 500m
memory: 1Gi
Requests:
cpu: 250m
memory: 256Mi
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-vzhz4 (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-vzhz4:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-vzhz4
Optional: false
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 51m default-scheduler Successfully assigned mq-svc-5b96bf78d9-brpjw to 10.0.0.17
Normal SuccessfulMountVolume 51m kubelet, 10.0.0.17 MountVolume.SetUp succeeded for volume "default-token-vzhz4"
Normal Pulling 51m kubelet, 10.0.0.17 pulling image "rabbitmq:management"
Normal Pulled 51m kubelet, 10.0.0.17 Successfully pulled image "rabbitmq:management"
Normal Created 51m kubelet, 10.0.0.17 Created container
Normal Started 51m kubelet, 10.0.0.17 Started container
其实有一个敏感的信息,pod是被一个名字为mq-svc-5b96bf78d9的ReplicaSet管理的,所以我们认为,RS是比Pod高一级别的专门用来管理pod的组件。一个RS会管理一批pod。
Controlled By: ReplicaSet/mq-svc-5b96bf78d9
而且在pod里面发生的实践也都是对容器的操作,比如拉取镜像、启动容器等等
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 51m default-scheduler Successfully assigned mq-svc-5b96bf78d9-brpjw to 10.0.0.17
Normal SuccessfulMountVolume 51m kubelet, 10.0.0.17 MountVolume.SetUp succeeded for volume "default-token-vzhz4"
Normal Pulling 51m kubelet, 10.0.0.17 pulling image "rabbitmq:management"
Normal Pulled 51m kubelet, 10.0.0.17 Successfully pulled image "rabbitmq:management"
Normal Created 51m kubelet, 10.0.0.17 Created container
Normal Started 51m kubelet, 10.0.0.17 Started container
- 接下来,我们就看看这个RS的详细情况
[root@VM_0_17_centos ~]# kubectl describe rs mq-svc-5b96bf78d9
Name: mq-svc-5b96bf78d9
Namespace: default
Selector: pod-template-hash=1652693485,qcloud-app=mq-svc
Labels: pod-template-hash=1652693485
qcloud-app=mq-svc
Annotations: deployment.changecourse=Updating
deployment.kubernetes.io/desired-replicas=1
deployment.kubernetes.io/max-replicas=2
deployment.kubernetes.io/revision=2
description=Service based on rabbitmq.
Controlled By: Deployment/mq-svc
Replicas: 1 current / 1 desired
Pods Status: 1 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: pod-template-hash=1652693485
qcloud-app=mq-svc
Containers:
queue-mq:
Image: rabbitmq:management
Port: <none>
Host Port: <none>
Limits:
cpu: 500m
memory: 1Gi
Requests:
cpu: 250m
memory: 256Mi
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 50m replicaset-controller Created pod: mq-svc-5b96bf78d9-r8n8t
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-l4zj2
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-m8tmv
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-m8tmv
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-r9wkj
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-8wzpq
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-d8gwc
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-d8gwc
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-8wzpq
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-l4zj2
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-r9wkj
Normal SuccessfulDelete 45m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-r8n8t
关键信息
Controlled By: Deployment/mq-svc
这个RS被名字为mq-svc的Deployment控制,这样看,Deployment是比RS高一级别用于管理RS的组件。
在RS级别上发生的事件,均是对pod的操作,创建pod,删除pod
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 50m replicaset-controller Created pod: mq-svc-5b96bf78d9-r8n8t
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-l4zj2
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-m8tmv
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-m8tmv
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-r9wkj
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-8wzpq
Normal SuccessfulCreate 49m replicaset-controller Created pod: mq-svc-5b96bf78d9-d8gwc
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-d8gwc
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-8wzpq
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-l4zj2
Normal SuccessfulDelete 49m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-r9wkj
Normal SuccessfulDelete 45m replicaset-controller Deleted pod: mq-svc-5b96bf78d9-r8n8t
- 接下来,我们来看看Delpoyment
[root@VM_0_17_centos ~]# kubectl describe deploy mq-svc
Name: mq-svc
Namespace: default
CreationTimestamp: Fri, 17 Aug 2018 17:21:13 +0800
Labels: qcloud-app=mq-svc
Annotations: deployment.changecourse=Updating
deployment.kubernetes.io/revision=2
description=Service based on rabbitmq.
Selector: qcloud-app=mq-svc
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 10
RollingUpdateStrategy: 0 max unavailable, 1 max surge
Pod Template:
Labels: qcloud-app=mq-svc
Containers:
queue-mq:
Image: rabbitmq:management
Port: <none>
Host Port: <none>
Limits:
cpu: 500m
memory: 1Gi
Requests:
cpu: 250m
memory: 256Mi
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: mq-svc-5b96bf78d9 (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 58m deployment-controller Scaled up replica set mq-svc-5b96bf78d9 to 2
Normal ScalingReplicaSet 57m deployment-controller Scaled up replica set mq-svc-5b96bf78d9 to 3
Normal ScalingReplicaSet 57m deployment-controller Scaled up replica set mq-svc-5b96bf78d9 to 4
Normal ScalingReplicaSet 57m deployment-controller Scaled down replica set mq-svc-5b96bf78d9 to 3
Normal ScalingReplicaSet 57m deployment-controller Scaled up replica set mq-svc-5b96bf78d9 to 6
Normal ScalingReplicaSet 57m deployment-controller Scaled down replica set mq-svc-5b96bf78d9 to 4
Normal ScalingReplicaSet 56m deployment-controller Scaled down replica set mq-svc-5b96bf78d9 to 2
Normal ScalingReplicaSet 53m deployment-controller Scaled down replica set mq-svc-5b96bf78d9 to 1
可以看出,在deployment级别上,不再受其他组件的控制,而他的状态的转变是作为API被调用而产生的。我们看到,在deployment级别上发生的事件一般是创建服务、滚动升级一个服务,或者是操作RS伸缩Pod集群。
最后,到这里也很明白了,service其实是在这一整套基础之上提供给外部的稳定的服务。
更多推荐
已为社区贡献1条内容
所有评论(0)