在上一篇文章中我们使用RC的方式创建了一个sonarqube的方式的pod,这篇文章中将会使用kubectl run的方式来创建一个pod,并会简单确认一下这两者有何不同。
构成说明
演示程序使用下列的集群构成。
No | type | IP | OS |
---|---|---|---|
1 | master | 192.168.32.131 | CENTOS7.2 |
2 | etcd | 192.168.32.131 | CENTOS7.2 |
3 | minion | 192.168.32.132 | CENTOS7.2 |
3 | minion | 192.168.32.133 | CENTOS7.2 |
3 | minion | 192.168.32.134 | CENTOS7.2 |
事前准备
事前将所需镜像提前pull下的各个minion节点
[root@host131 ~]# for h in host132 host133 host134
> do
> echo "$h"
> ssh $h docker images |grep sonarqube
> done
host132
docker.io/sonarqube latest eea2f3093d50 5 days ago 790.9 MB
host133
docker.io/sonarqube latest eea2f3093d50 Less than a second ago 790.9 MB
host134
docker.io/sonarqube latest eea2f3093d50 Less than a second ago 790.9 MB
[root@host131 ~]#
事前确认
事前确认:没有pod
[root@host131 ~]# kubectl get pods
[root@host131 ~]#
创建pod
[root@host131 ~]# kubectl run example --image=sonarqube
deployment "example" created
[root@host131 ~]#
确认pod的创建结果
确认已经是running状态
[root@host131 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
example-3821493920-c7c8v 1/1 Running 0 1m
[root@host131 ~]#
确认pod所在的node
我们有3个node,到底是在哪台node上运行这个pod呢
[root@host131 ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE NODE
example-3821493920-c7c8v 1/1 Running 1 6m host134
[root@host131 ~]#
通过rancher,也可以确认到在host134上跑这个这个example-3821493920-c7c8v
describe pod
通过kubectl describe pod来确认一下详细信息,可以和RC创建的方式进行比较。
[root@host131 ~]# kubectl describe pod example-3821493920-c7c8v
Name: example-3821493920-c7c8v
Namespace: default
Node: host134/192.168.32.134
Start Time: Tue, 30 Aug 2016 13:01:03 -0400
Labels: pod-template-hash=3821493920,run=example
Status: Running
IP: 172.16.64.5
Controllers: ReplicaSet/example-3821493920
Containers:
example:
Container ID: docker://363971c9af13a301a3998c54957bc0579f78e66f66d2064ee61940bb49325f54
Image: sonarqube
Image ID: docker://sha256:eea2f3093d50fde1a5cf90faea4e20b6cc966768885ee9b264ec2c616d803cd2
Port:
QoS Tier:
cpu: BestEffort
memory: BestEffort
State: Terminated
Reason: Completed
Exit Code: 0
Started: Tue, 30 Aug 2016 13:01:39 -0400
Finished: Tue, 30 Aug 2016 13:04:22 -0400
Ready: False
Restart Count: 0
Environment Variables:
Conditions:
Type Status
Ready False
Volumes:
default-token-8209b:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-8209b
Events:
FirstSeen LastSeen Count From SubobjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
7d 7d 1 {kubelet host134} spec.containers{example} Normal Pulling pulling image "sonarqube"
7d 7d 1 {kubelet host134} spec.containers{example} Normal Pulled Successfully pulled image "sonarqube"
7d 7d 1 {kubelet host134} spec.containers{example} Normal Created Created container with docker id 363971c9af13
7d 7d 1 {kubelet host134} spec.containers{example} Normal Started Started container with docker id 363971c9af13
3m 3m 1 {default-scheduler } Normal Scheduled Successfully assigned example-3821493920-c7c8v to host134
[root@host131 ~]#