使用rancher+docker+k8s搭建集群管理平台


安裝docker-ce-17.03.2

#安裝docker-ce-17.03.2,首先要安裝它的依賴包
[root@linux-node2 ~]# wget  https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm --no-check-certificate
[root@linux-node2 ~]# yum install -y  docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm 
#安裝docker-ce-17.03.2
[root@linux-node2 ~]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm --no-check-certificate
[root@linux-node2 ~]# yum  install -y docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm 
#驗證docker-ce是否安裝成功,查看docker-ce的版本
[root@linux-node2 ~]# docker version
Client:
 Version:      17.03.2-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   f5ec1e2
 Built:        Tue Jun 27 02:21:36 2017
 OS/Arch:      linux/amd64

啟動docker,下載rancher並啟動rancher容器

[root@linux-node2 ~]# systemctl  start  docker
[root@linux-node2 ~]# docker  pull  rancher/server:v1.6.14
#運行rancher容器,報錯如下:
[root@linux-node2 ~]# docker  run  -d  --restart=unless-stopped -p 8080:8080 rancher/server:v1.6.14
docker: Error response from daemon: mkdir /var/lib/docker/overlay/138a6139ced9986f759c7f8514a4f706168140aaf10fa70f9e50a1ad3187dcbc-init/merged/dev/shm: invalid argument.
#解決辦法:參考https://stackoverflow.com/questions/42248571/cannt-run-or-build-docker-images-on-centos-7
[root@linux-node2 docker]# vim  /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://0wtxe175.mirror.aliyuncs.com"],
  "storage-driver": "devicemapper"
}
[root@linux-node2 docker]# systemctl  daemon-reload
[root@linux-node2 docker]# systemctl  start docker
#最后再啟動rancher容器,成功了
[root@linux-node2 docker]# docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                              NAMES
fa0517e043d8        rancher/server:v1.6.14   "/usr/bin/entry /u..."   16 minutes ago      Up 16 minutes       3306/tcp, 0.0.0.0:8080->8080/tcp   awesome_hypatia

 

創建一個編排hello.yaml后,狀態一直是ContainerCreating,經查看生成過程,排錯如下

[root@linux-node1 ~]# kubectl  create  -f  hello.yaml 
pod "hello-world" created
[root@linux-node1 ~]# kubectl  get  pods
NAME          READY     STATUS              RESTARTS   AGE
hello-world   0/1       ContainerCreating   0          6s
#一直處於ContainerCreating狀態,查看生成過程
[root@linux-node1 ~]# kubectl  get  pods
NAME          READY     STATUS              RESTARTS   AGE
hello-world   0/1       ContainerCreating   0          7m
[root@linux-node1 ~]# kubectl describe pod  hello-world
Name:           hello-world
Namespace:      default
Node:           192.168.182.171/192.168.182.171
。。。
。。。
arning          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)"

  10m   15s     43      {kubelet 192.168.182.171}               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\""
#上面的報錯原因為不能打開這個文件/etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt
#通過ll 查看這個文件是否存在,狀態是軟連接,不停閃爍,說明這個軟件接有問題,證書不存在
[root@linux-node2 ~]# ll /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt
lrwxrwxrwx 1 root root 27 Jul 19 14:02 /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt -> /etc/rhsm/ca/redhat-uep.pem
#接下來就要生成這個證書文件,注意:是在node節點生成這個證書,而不是master節點
[root@linux-node2 ~]# yum install python-rhsm* -y
Installed:
  subscription-manager-rhsm.x86_64 0:1.20.11-1.el7.centos                                                              
  subscription-manager-rhsm-certificates.x86_64 0:1.20.11-1.el7.centos 
#安裝的subscription-manager-rhsm-certificates.x86_64 0:1.20.11-1.el7.centos並不是我們需要的證書安裝包,所以要把這個包卸載掉,下載正確的證書安裝包
[root@linux-node2 ~]# yum  remove  subscription-manager-rhsm-certificates.x86_64 0:1.20.11-1.el7.centos 
[root@linux-node2 ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
[root@linux-node2 ~]# yum  install  python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm 
#這時候再打開這個證書文件軟連接就正常了
[root@linux-node2 ~]# ll  /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt
lrwxrwxrwx 1 root root 27 Jul 19 14:11 /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt -> /etc/rhsm/ca/redhat-uep.pem
#最后重新創建一個編排后,node節點就可以pull拉取對應的images了

 

 

k8s dashboard 報錯 Error: 'dial tcp 172.168.56.2:9090: getsockopt: connection refused'

檢查iptables -L -n ,檢查node節點上的FORWARD 查看轉發是否是drop,如果是drop,則開啟

解決辦法:iptables -P FORWARD ACCEPT   不過系統重啟后就失效了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM