[root@centos ~]# kubectl create -f mysql-rc.yaml replicationcontroller "mysql" created
提示如下错误请注意yaml 文件的格式是否正确以及配置参数是否输入正确
error: error validating "mysql-rc.yaml": error validating data: kind not set; if you choose to ignore these errors, turn validation off with --validate=false
查看 RC
[root@centos ~]# kubectl get rc NAME DESIRED CURRENT READY AGE mysql 1 1 0 1m
查看 Pod
[root@centos ~]# kubectl get pods NAME READY STATUS RESTARTS AGE mysql-cvg6c 0/1 ContainerCreating 03m
我们看到一个名为 mysql-xxxx的 Pod 实例,这是 k8s 根据 mysql 的这个 RC 文件的定义自动创建的 Pod。 由于其创建需要一些时间,因此我们一开始看到的 Pod 状态是 Pending,待最终完成会被更新为 Running
但是我们这边看到的状态是 ContainerCreating ,我们执行
[root@centos ~]# kubectl describe pod mysql Name: mysql-cvg6c Namespace: default Node:127.0.0.1/127.0.0.1 Start Time: Sat, 03 Mar 201809:22:42+0800 Labels: app=mysql Status: Pending IP: Controllers: ReplicationController/mysql Containers: mysql: Container ID: Image: mysql Image ID: Port:3306/TCP State: Waiting Reason: ContainerCreating Ready: False Restart Count:0 Volume Mounts:<none> Environment Variables: MYSQL_ROOT_PASSWORD:123456 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 --------- -------- ----- ---- ------------- -------- ------ ------- 8m 8m 1 {default-scheduler } Normal Scheduled Successfully assigned mysql-cvg6c to 127.0.0.1 8m 3m 6 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD"withErrImagePull:"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)"
8m 12s 35 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD"withImagePullBackOff:"Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""
可以看出是镜像下载失败了
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)"
[root@centos~]# kubectl create-f mysql-rc.yaml replicationcontroller "mysql" created [root@centos~]# kubectl get rc NAME DESIRED CURRENT READY AGE mysql 11010s [root@centos~]# kubectl get pods NAME READY STATUS RESTARTS AGE mysql-7blh0 0/1 ContainerCreating 013s mysql-cvg6c 0/1 Terminating 021m
发现还是不行
[root@centos ~]# kubectl describe pods mysql Name: mysql-j6vpx Namespace: default Node:127.0.0.1/127.0.0.1 Start Time: Sat, 03 Mar 201809:51:30+0800 Labels: app=mysql Status: Pending IP: Controllers: ReplicationController/mysql Containers: mysql: Container ID: Image: mysql Image ID: Port:3306/TCP State: Waiting Reason: ContainerCreating Ready: False Restart Count:0 Volume Mounts:<none> Environment Variables: MYSQL_ROOT_PASSWORD:123456 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 --------- -------- ----- ---- ------------- -------- ------ ------- 59m 59m 1 {default-scheduler } Normal Scheduled Successfully assigned mysql-j6vpx to 127.0.0.1 32m 32m 1 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy. 32m 32m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Pulling pulling image "mysql" 1m 1m 1 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy. 59s 59s 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Pulling pulling image "mysql"
[root@centos~]# kubectl get pods NAME READY STATUS RESTARTS AGE mysql-j6vpx 1/1Running01h
然后 在使用 kubectl describe pods mysql 查看
[root@centos ~]# kubectl describe pods mysql Name: mysql-j6vpx Namespace: default Node:127.0.0.1/127.0.0.1 Start Time: Sat, 03 Mar 201809:51:30+0800 Labels: app=mysql Status: Running IP:172.17.0.2 Controllers: ReplicationController/mysql Containers: mysql: Container ID: docker://0f1032ef9bd08438996e76c98f7f313b73a07ade76bf6b4b6b5c42de8dcba053 Image: mysql Image ID: docker-pullable://docker.io/mysql@sha256:227d5c3f54ee3a70c075b1c3013e72781564000d34fc8c7ec5ec353c5b7ef7fa Port:3306/TCP State: Running Started: Sat, 03 Mar 201810:51:26+0800 Ready: True Restart Count:0 Volume Mounts:<none> Environment Variables: MYSQL_ROOT_PASSWORD:123456 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 --------- -------- ----- ---- ------------- -------- ------ ------- 33m 33m 1 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy. 33m 33m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Pulling pulling image "mysql" 2m 2m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Pulling pulling image "mysql" 2m 1m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy. 1m 1m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Pulled Successfully pulled image "mysql" 1m 1m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Created Created container with docker id 0f1032ef9bd0; Security:[seccomp=unconfined] 1m 1m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Started Started container with docker id 0f1032ef9bd0
使用docker ps -a 查看
[root@centos ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0f1032ef9bd0 mysql "docker-entrypoint.sh"6 minutes ago Up 6 minutes k8s_mysql.f6601b53_mysql-j6vpx_default_64fa560c-1e85-11e8-b481-fa163eee21c2_2999ac54 19334c061120 registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod"7 minutes ago Up 7 minutes k8s_POD.1d520ba5_mysql-j6vpx_default_64fa560c-1e85-11e8-b481-fa163eee21c2_3a9e5664 f72b01ab8585 registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod"38 minutes ago Exited (0) 7 minutes ago k8s_POD.1d520ba5_mysql-j6vpx_default_64fa560c-1e85-11e8-b481-fa163eee21c2_a7bd20de
节点状态
节点的状态主要是用来描述处于 Running 的节点。当前可用的有 NodeReachable 和 NodeReady。以后可能会增加其他状态。NodeReachable 表示集群可达。NodeReady 表示 kubelet 返回 Status Ok 并且 HTTP 状态检查健康。
[root@centos ~]# kubectl create -f myweb-svc.yaml service "myweb" created
查看 Service
[root@centos ~]# kubectl get services NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes 10.254.0.1<none>443/TCP22h mysql 10.254.248.63<none>3306/TCP9h myweb 10.254.193.35<nodes>8080:30001/TCP32s
删除 rc
[root@centos ~]# kubectl delete -f myweb-rc.yaml
查看 rc
[root@centos ~]# kubectl get rc NAME DESIRED CURRENT READY AGE mysql 1 1 1 11h myweb 5 5 0 4s