k8s 編排第一個POD 時候container creating 的問題

1: 今天開始k8s 的的實踐啦:

示例:實現 運行在 Tomcat裏的 Web app,JSP頁面通過 JDBC 直接訪問 MySQL數據庫並展示數據。

需求:Web App 容器 MySQL容器,web--->mysql

         需要把MySQL容器的IP地址通過環境變量的方式注入 Web App容器裏,同時,需要將Web App容器的 8080端口映射宿主機的 8080端口,以便在外部訪問。

1: 先編寫第一個yaml 文件;

1.YAML編寫

1.MySQL服務創建一個 RC 文件

# cat mysql-rc.yaml
apiVersion: apps/v1beta1    (把這行改成:apiVersion: extensions/v1beta1  就不報錯啦 )
kind: Deployment
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:5.7
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"

創建好以後:

[root@k8s-master script]# kubectl get pods
NAME                     READY     STATUS              RESTARTS   AGE
mysql-4144028371-3v7nb   0/1       ContainerCreating   0          28s

然後trouble shooting :

kubectl describe pod

發現如下的報錯:

    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)"

image 沒有pull:

下面一步步解決:

systemctl daemon-reload
service docker restart
service docker status (should see active (running))

[root@k8s-master script]# 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

發現還是少證書。

下面實踐瞭解決方法:

 ①   wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm

     ②   rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem    

       前兩個命令會生成/etc/rhsm/ca/redhat-uep.pem文件.     

       ③    docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
成功了:

[root@k8s-master ca]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...
latest: Pulling from registry.access.redhat.com/rhel7/pod-infrastructure
26e5ed6899db: Pull complete
66dbe984a319: Pull complete
9138e7863e08: Pull complete
Digest: sha256:92d43c37297da3ab187fc2b9e9ebfb243c1110d446c783ae1b989088495db931
Status: Downloaded newer image for registry.access.redhat.com/rhel7/pod-infrastructure:latest

 

-----

注意: 上面的操作在node 上都要再做一遍。

2: 下面把rc 刪除了重新建:

kubectl delete -f mysql-rc.yaml

kubectl create -f mysql-rc.yaml

3: 重起一下server, 或者 master,node 上的服務,就好了:

[root@k8s-master script]# kubectl get pod
NAME                     READY     STATUS    RESTARTS   AGE
mysql-4144028371-l6d0m   1/1       Running   0          41m

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章