kubernetes云平台管理实战: 最小的资源pod(二)
一、pod初体验
1、编辑k8s_pod.yml文件
[root@k8s-master ~]# cat k8s_pod.yml apiVersion: v1 kind: Pod metadata: name: nginx labels: app: web spec: containers: - name: nginx image: 10.0.128.0:5000/nginx:latest ports: - containerPort: 80
2、下载镜像并上传到私有仓库
[root@k8s-master ~]# docker pull nginx:latest Trying to pull repository docker.io/library/nginx ... latest: Pulling from docker.io/library/nginx 177e7ef0df69: Pull complete ea57c53235df: Pull complete bbdb1fbd4a86: Pull complete Digest: sha256:b543f6d0983fbc25b9874e22f4fe257a567111da96fd1d8f1b44315f1236398c [root@k8s-master ~]# docker tag nginx:latest 10.0.128.0:5000/nginx:latest [root@k8s-master ~]# docker push 10.0.128.0:5000/nginx:latest The push refers to a repository [10.0.128.0:5000/nginx] b7efe781401d: Pushed c9c2a3696080: Pushed 7b4e562e58dc: Pushed latest: digest: sha256:e2847e35d4e0e2d459a7696538cbfea42ea2d3b8a1ee8329ba7e68694950afd3 size: 948
3、启动pod
[root@k8s-master ~]# kubectl create -f k8s_pod.yml pod "nginx" created [root@k8s-master ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e166a705c0a7 busybox "/bin/sh" 31 minutes ago Exited (0) 10 minutes ago cranky_bardeen ba8d9b958c7c registry "/entrypoint.sh /etc/" 44 minutes ago Up 44 minutes 0.0.0.0:5000->5000/tcp registry 15340ee09614 busybox "/bin/sh" 4 hours ago Exited (1) About an hour ago sleepy_mccarthy
二、无法创建pod故障现象
1、查看pod状态
[root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE nginx 0/1 ContainerCreating 0 2m
2、获取pod详细信息(拍错常用命令)
[root@k8s-master ~]# kubectl describe pod nginx Name: nginx Namespace: default Node: k8s-node1/10.0.128.1 Start Time: Sun, 20 Jan 2019 13:04:51 +0800 Labels: app=web Status: Pending IP: Controllers: <none> Containers: nginx: Container ID: Image: 10.0.128.0:5000/nginx:latest Image ID: Port: 80/TCP State: Waiting Reason: ContainerCreating Ready: False Restart Count: 0 Volume Mounts: <none> Environment Variables: <none> Conditions: Type Status Initialized True Ready False PodScheduled True No volumes. QoS Class: BestEffort Tolerations: <none> Events: FirstSeen LastSeen Count From SubObjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 3m 3m 1 {default-scheduler } Normal Scheduled Successfully assigned nginx to k8s-node1 3m 46s 5 {kubelet k8s-node1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)" 3m 8s 12 {kubelet k8s-node1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""
错误是无法从registry.access.redhat.com仓库获取镜像,解决办法是更换镜像地址
三、pod故障解决方案
1、搜索pod-infrastructure
[root@k8s-master ~]# docker search pod-infrastructure
2、下载并上传到私有仓库
[root@k8s-master ~]# docker pull tianyebj/pod-infrastructure Using default tag: latest Trying to pull repository docker.io/tianyebj/pod-infrastructure ... latest: Pulling from docker.io/tianyebj/pod-infrastructure 7bd78273b666: Pull complete c196631bd9ac: Pull complete 3c917e6a9e1a: Pull complete Digest: sha256:73cc48728e707b74f99d17b4e802d836e22d373aee901fdcaa781b056cdabf5c [root@k8s-master ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/registry latest 33fbbf4a24e5 2 weeks ago 24.17 MB 10.0.128.0:5000/busybox latest 3a093384ac30 2 weeks ago 1.199 MB docker.io/busybox latest 3a093384ac30 2 weeks ago 1.199 MB 10.0.128.0:5000/nginx latest 7042885a156a 3 weeks ago 109.2 MB docker.io/nginx latest 7042885a156a 3 weeks ago 109.2 MB docker.io/tianyebj/pod-infrastructure latest 34d3450d733b 24 months ago 205 MB [root@k8s-master ~]# docker tag docker.io/tianyebj/pod-infrastructure:latest 10.0.128.0:5000/pod-infrastructure:latest [root@k8s-master ~]# docker push 10.0.128.0:5000/pod-infrastructure:latest The push refers to a repository [10.0.128.0:5000/pod-infrastructure] ba3d4cbbb261: Pushed 0a081b45cb84: Pushed df9d2808b9a9: Pushed latest: digest: sha256:a378b2d7a92231ffb07fdd9dbd2a52c3c439f19c8d675a0d8d9ab74950b15a1b size: 948
3、修改镜像的地址
vim /etc/kubernetes/kubelet 修改内容如下: KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=10.0.128.0:5000/pod-infrastructure:latest"
4、再次查看pod详细信息
[root@k8s-master ~]# kubectl describe pod nginx Name: nginx Namespace: default Node: k8s-node1/10.0.128.1 Start Time: Sun, 20 Jan 2019 13:04:51 +0800 Labels: app=web Status: Running IP: 172.16.10.2 Controllers: <none> Containers: nginx: Container ID: docker://27d25a2ee0248b103991a27b81e3f244382ebdb642694e2aeb5503c373fdb912 Image: 10.0.128.0:5000/nginx:latest Image ID: docker-pullable://10.0.128.0:5000/nginx@sha256:e2847e35d4e0e2d459a7696538cbfea42ea2d3b8a1ee8329ba7e68694950afd3 Port: 80/TCP State: Running Started: Sun, 20 Jan 2019 13:48:30 +0800 Ready: True Restart Count: 0 Volume Mounts: <none> Environment Variables: <none> Conditions: Type Status Initialized True Ready True PodScheduled True No volumes. QoS Class: BestEffort Tolerations: <none> Events: FirstSeen LastSeen Count From SubObjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 48m 48m 1 {default-scheduler } Normal Scheduled Successfully assigned nginx to k8s-node1 48m 6m 13 {kubelet k8s-node1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)" 47m 5m 182 {kubelet k8s-node1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\"" 4m 4m 1 {kubelet k8s-node1} spec.containers{nginx} Normal Pulling pulling image "10.0.128.0:5000/nginx:latest" 4m 4m 2 {kubelet k8s-node1} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy. 4m 4m 1 {kubelet k8s-node1} spec.containers{nginx} Normal Pulled Successfully pulled image "10.0.128.0:5000/nginx:latest" 4m 4m 1 {kubelet k8s-node1} spec.containers{nginx} Normal Created Created container with docker id 27d25a2ee024; Security:[seccomp=unconfined] 4m 4m 1 [root@k8s-master ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE nginx 1/1 Running 0 48m 172.16.10.2 k8s-node1 [root@k8s-master ~]# curl 172.16.10.2 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> elet k8s-node1} spec.containers{nginx} Normal Started Started container with docker id 27d25a2ee024
作者:罗阿红
出处:http://www.cnblogs.com/luoahong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。