在看《k8s權(quán)威指南》實戰(zhàn)過程中遇到了一個問題:
我打算發(fā)布一個mysql-rc.yaml到集群中,我的mysql-rc.yaml文件是這樣的
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
spec:
replicas: 1
#定義RC標簽選擇
selector:
app: mysql
#定義Pod模板
template:
metadata:
labels:
app: mysql
spec:
#Pod內(nèi)容器定義
containers:
- name: mysql
image: mysql
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
發(fā)布到集群出現(xiàn)問題:
[root@kubecon ~]# kubectl create -f mysql-rc.yaml
replicationcontroller "mysql" created
[root@kubecon ~]# kubectl get rc
NAME DESIRED CURRENT READY AGE
mysql 1 1 0 1m
[root@kubecon ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
mysql-bwnlk 0/1 ContainerCreating 0 1m
pod服務(wù)一直處于 ContainerCreating狀態(tài)
Solution
查看相關(guān)日志
[root@kubecon ~]# kubectl describe po mysql-bwnlk
Name: mysql-bwnlk
Namespace: default
Node: 127.0.0.1/127.0.0.1
Start Time: Thu, 04 Jan 2018 10:20:45 +0800
Labels: app=mysql
Status: Pending
IP:
Controllers: ReplicationController/mysql
Containers:
mysql:
Container ID:
Image: daocloud.io/library/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
--------- -------- ----- ---- ------------- -------- ------ -------
3m 3m 1 {default-scheduler } Normal Scheduled Successfully assigned mysql-bwnlk to 127.0.0.1
3m 20s 5 {kubelet 127.0.0.1} 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)"
2m 8s 10 {kubelet 127.0.0.1} 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\""
關(guān)鍵問題出現(xiàn)
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)"
看到registry.access.redhat.com/rhel7/pod-infrastructure:latest我感覺很怪希坚,我之前已經(jīng)設(shè)置好倉庫為grc.io殴穴,為什么去拉取這個鏡像柴钻,懷疑是不是什么沒有安裝好淮韭。
嘗試運行docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest,提示redhat-ca.crt: no such file or directory贴届。
[root@kubecon ~]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...
open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory
ls查看該文件是個軟連接靠粪,鏈接目標是/etc/rhsm
[root@kubecon ~]# ls -l /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt
lrwxrwxrwx 1 root root 27 1月 3 21:06 /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt -> /etc/rhsm/ca/redhat-uep.pem
查看沒有rhsm
[root@kubecon ~]# ls /etc/rhsm
ls: 無法訪問/etc/rhsm: 沒有那個文件或目錄
嘗試安裝yum install rhsm
yum install rhsm -y
#如果上一步?jīng)]有源的話足丢,請試試
#yum -y install python-rhsm
#如果上一步還不能安裝rhsm的話請下載rpm包安裝
#https://www.rpmfind.net/linux/rpm2html/search.php?query=python-rhsm
#wget https://www.rpmfind.net/linux/centos/7.4.1708/os/x86_64/Packages/python-rhsm-1.19.9-1.el7.x86_64.rpm
#rpm -ivh python-rhsm-*.rpm
安裝之后查看產(chǎn)生了/etc/rhsm文件夾,再次運行kubectl get pods
問題解決~
[root@kubecon ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
mysql-bwnlk 1/1 Running 0 52m