➜ nexus kubectl create -f test.yaml pod "rbd-rest-api-using-node-config" created ➜ nexus kubectl get pods NAME READY STATUS RESTARTS AGE nexus3-68f55d9746-vfnf8 1/1 Running 017h rbd-rest-api-using-node-config 0/1 ImagePullBackOff 05s
通过log查看Pod:
1 2 3
➜ nexus kubectl logs pod/rbd-rest-api-using-node-config Error from server (BadRequest): container "rbd-rest-api-using-node-config" in pod "rbd-rest-api-using-node-config" is waiting to start: trying and failing to pull image ➜ nexus
通过describe查看pod失败的更加详细的信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
➜ nexus kubectl describe pod/rbd-rest-api-using-node-config .... 前面部分省略 .... QoS Class: BestEffort Node-Selectors: kubernetes.io/hostname=192.168.1.16 Tolerations: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 13m default-scheduler Successfully assigned rbd-rest-api-using-node-config to192.168.1.16 Normal SuccessfulMountVolume 13m kubelet, 192.168.1.16 MountVolume.SetUp succeeded for volume "default-token-fck44" Normal SandboxChanged 13m kubelet, 192.168.1.16 Pod sandbox changed, it will be killed and re-created. Warning Failed 12m (x3 over13m) kubelet, 192.168.1.16 Failed to pull image "registry.martin.com:5000/registry": rpc error: code =Unknowndesc= Error response from daemon: Get https://registry.martin.com:5000/v2/registry/manifests/latest: no basic auth credentials Normal Pulling 11m (x4 over13m) kubelet, 192.168.1.16 pulling image "registry.martin.com:5000/registry" Warning Failed 11m (x4 over13m) kubelet, 192.168.1.16 Error: ErrImagePull Normal BackOff 8m (x21 over13m) kubelet, 192.168.1.16 Back-off pulling image "registry.martin.com:5000/registry" Warning Failed 3m (x42 over13m) kubelet, 192.168.1.16 Error: ImagePullBackOff ➜ nexus
➜ nexus kubectl delete pod rbd-rest-api-using-node-config pod "rbd-rest-api-using-node-config" deleted ➜ nexus kubectl get pods NAME READY STATUS RESTARTS AGE 已经没有该pod了
➜ nexus kubectl get secret NAME TYPE DATA AGE default-token-fck44 kubernetes.io/service-account-token 3 15d 可以看到之前已经有个default-token的secret ➜ nexus ➜ nexus kubectl create secret docker-registry registrykey-2.6.2 --docker-server=registry.martin.com:5000 --docker-username=martin --docker-password=xxx1 --docker-email=hanniusshine@gmail.com secret "registrykey-2.6.2" created
➜ nexus kubectl get secret NAME TYPE DATA AGE default-token-fck44 kubernetes.io/service-account-token 3 15d registrykey-2.6.2 kubernetes.io/dockerconfigjson 1 3s ➜ nexus
➜ nexus kubectl create -f test.yaml The Pod "rbd-rest-api-registrykey-m2.6.2-1"is invalid: spec.containers[0].name: Invalid value: "rbd-rest-api-registrykey-m2.6.2-1": a DNS-1123 label must consist of lowercase alphanumeric characters or'-', and must startandendwith an alphanumeric character (e.g. 'my-name', or'123-abc', regex used for validation is'[a-z0-9]([-a-z0-9]*[a-z0-9])?') 原来container的name命名只能用小写字母和-,不能用.号,所以修改name为:"rbd-rest-api-registrykey-m262-1"
再次创建ok: ➜ nexus kubectl create -f test.yaml pod "rbd-rest-api-registrykey-m262-1" created ➜ nexus ➜ nexus kubectl get pods NAME READY STATUS RESTARTS AGE nexus3-68f55d9746-vfnf8 1/1 Running 018h rbd-rest-api-registrykey-m262-11/1 Running 06s ➜ nexus
通过describe pod,查看创建的event序列:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
➜ nexus kubectl describe pod/rbd-rest-api-registrykey-m262-1 ... 部分省略 ... Events: Type Reason Age From Message ------------------------- Normal Scheduled 1m default-scheduler Successfully assigned rbd-rest-api-registrykey-m262-1 to 192.168.1.16 Normal SuccessfulMountVolume 1m kubelet, 192.168.1.16 MountVolume.SetUp succeeded for volume "default-token-fck44" Normal Pulling 1m kubelet, 192.168.1.16 pulling image "registry.martin.com:5000/registry" Normal Pulled 1m kubelet, 192.168.1.16 Successfully pulled image "registry.martin.com:5000/registry" Normal Created 1m kubelet, 192.168.1.16 Created container Normal Started 1m kubelet, 192.168.1.16 Started container ➜ nexus
正如期望的那样,引用了secret: registrykey-2.6.2的Pod成功Run起来了。
查看指定运行pod的节点是否run了对应的image:
1 2 3
[root@node3 docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 457e48f68bd7 registry.martin.com:5000/registry "/entrypoint.sh /e..." 6 minutes ago Up 5 minutes k8s_rbd-rest-api-registrykey-m262-1_rbd-rest-api-registrykey-m262-1_default_1265c1f5-75f3-11e8-8760-5254004f2222_0
➜ nexus kubectl get secret NAME TYPE DATA AGE default-token-fck44 kubernetes.io/service-account-token 3 15d registrykey-2.6.2 kubernetes.io/dockerconfigjson 1 3s registrykey-2.6.3 kubernetes.io/dockerconfigjson 1 3s ➜ nexus
# kubectl create -f test2.yaml pod"rbd-rest-api-multi-registrykeys-m262-2" created
# kubectl get pod NAME READY STATUS RESTARTS AGE rbd-rest-api-multi-registrykeys-m262-22/2 Running 05s
通过pod的event,看下启动的操作顺序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 1m default-scheduler Successfully assigned rbd-rest-api-registrykey-m262-1 to 192.168.1.16 Normal SuccessfulMountVolume 1m kubelet, 192.168.1.16 MountVolume.SetUp succeeded for volume "default-token-fck44" Normal Pulling 1m kubelet, 192.168.1.16 pulling image "registry.martin.com:5000/registry" Normal Pulled 1m kubelet, 192.168.1.16 Successfully pulled image "registry.martin.com:5000/registry" Normal Created 1m kubelet, 192.168.1.16 Created container Normal Started 1m kubelet, 192.168.1.16 Started container Normal Pulling 1m kubelet, 192.168.1.16 pulling image "registry.martin.com:6000/registry" Normal Pulled 1m kubelet, 192.168.1.16 Successfully pulled image "registry.martin.com:6000/registry" Normal Created 1m kubelet, 192.168.1.16 Created container Normal Started 1m kubelet, 192.168.1.16 Started container ➜ nexus
➜ nexus kubectl create-f test3.yaml pod "rbd-rest-api-registrykey-m262-3" created ➜ nexus kubectl get pod NAME READY STATUS RESTARTS AGE nexus3-68f55d9746-vfnf8 1/1Running03d rbd-rest-api-registrykey-m262-11/1Running02d rbd-rest-api-registrykey-m262-30/1 CrashLoopBackOff 17s ➜ nexus ➜ nexus kubectl describe pod rbd-rest-api-registrykey-m262-3 Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 39s default-scheduler Successfully assigned rbd-rest-api-registrykey-m262-3to192.168.1.16 Normal SuccessfulMountVolume 39s kubelet, 192.168.1.16 MountVolume.SetUp succeeded for volume "default-token-fck44" Normal Pulling 22s (x3 over38s) kubelet, 192.168.1.16 pulling image "registry.martin.com:5000/os/alpine" Normal Pulled 22s (x3 over38s) kubelet, 192.168.1.16 Successfully pulled image "registry.martin.com:5000/os/alpine" Normal Created 22s (x3 over38s) kubelet, 192.168.1.16 Created container Normal Started 22s (x3 over37s) kubelet, 192.168.1.16 Started container Warning BackOff 7s (x4 over36s) kubelet, 192.168.1.16 Back-off restarting failed container
➜ nexus kubectl get pod NAME READY STATUS RESTARTS AGE nexus3-68f55d9746-vfnf8 1/1Running03d rbd-rest-api-registrykey-m262-11/1Running02d rbd-rest-api-registrykey-m262-31/1Running350s