最近刚刚入手研究kubernetes,运行容器的时候,发现一直处于ContainerCreating状态,悲了个催,刚入手就遇到了点麻烦,下面来讲讲如何查找问题及解决的
运行容器命令:
[root@master-149 ~]# kubectl run my-alpine --image=alpine --replicas=2 ping www.baidu.com
查看pods状态
[root@master-149 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
my-alpine-2150523991-knzcx 0/1 ContainerCreating 0 6m
my-alpine-2150523991-lmvv5 0/1 ContainerCreating 0 6m
一直处于ContainerCreating状态,开始查找原因
执行如下命令:
[root@master-149 ~]# kubectl describe pod my-alpine
Name: my-alpine-2150523991-knzcx
Namespace: default
Node: node-150/192.168.10.150
Start Time: Sat, 19 Nov 2016 18:20:52 +0800
Labels: pod-template-hash=2150523991,run=my-alpine
Status: Pending
IP:
Controllers: ReplicaSet/my-alpine-2150523991
Containers:
my-alpine:
Container ID:
Image: alpine
Image ID:
Port:
Args:
ping
w
某些特殊情况下,需要将某些服务固定在一台宿主机上,K8S也适应这种方式,下面以mongo为例,来看看如何实现的:
kubectl label nodes kube-node node=kube-node
kubectl get node -a -l "node=kube-node"
pod或者rc的配置项中添加如下配置:
nodeSelector:
node: kube-node4
如mongo启动的rc文件
apiVersion: v1
kind: ReplicationController
metadata:
name: mongo
spec:
replicas: 1
template:
metadata:
labels:
run: mongo
spec:
containers:
- name: mongo
image: daocloud.io/library/mongo:3.2.4
ports:
- containerPort: 27017
volumeMounts:
- mountPath: /data/db
name: mongo
volumes: [{"name":"mongo","hostPath":{"path":"/root/volumes/mongo"}}]
nodeSelector:
node: kube-node4
by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(==防止爬虫==):http://blog.liuyingguang.cn