k8s-master 和 k8s-slave一、k8s-slave2 爲了上網,都是雙網卡(NAT和Host-only)html
sudo ufw disable
node
sudo swapoff -a
linux
sudo apt-get remove docker docker-engine docker.io
完全刪除docker-ce和docker-cligit
sudo apt-get autoremove docker-ce
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
爲了使用https訪問,使用阿里雲加速github
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \ $(lsb_release -cs) \ stable"
更新源docker
sudo apt update && sudo apt-get update
查看docker-ce版本json
apt-cache madison docker-ce
安裝指定版本ubuntu
sudo apt-get install -y docker-ce=18.06.3~ce~3-0~ubuntu
若是由於libltdl版本低,能夠安裝新版本 wget http://launchpadlibrarian.net/236916213/libltdl7_2.4.6-0.1_amd64.deb && sudo dkpg -i libltdl7_2.4.6-0.1_amd64.deb
api
sudo systemctl enable docker && sudo systemctl start docker
$ sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com"] } EOF
將xxxxxx替換爲在阿里雲申請的路徑網絡
sudo apt-get update && sudo apt-get install -y apt-transport-https curl sudo curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add - sudo tee /etc/apt/sources.list.d/kubernetes.list <<-'EOF' deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main EOF sudo apt-get update
在master和node都安裝
sudo apt-get install -y kubelet=1.12.8-00 kubeadm=1.12.8-00 kubectl=1.12.8-00 sudo apt-mark hold kubelet=1.12.8-00 kubeadm=1.12.8-00 kubectl=1.12.8-00
sudo systemctl enable kubelet && sudo systemctl start kubelet
sudo kubeadm init --apiserver-advertise-address 192.168.56.112 --pod-network-cidr=10.244.0.0/16 --kubernetes-version=1.12.8
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
sudo kubeadm join 192.168.56.112:6443 --token xxxxxx --discovery-token-ca-cert-hash sha256:xxxxxxxx
將以前kubeadm init後,輸出的加入node指令拷貝到node執行。
journalctl -u kubelet 看到報錯: failed to load Kubelet config file /var/lib/kubelet/config.yaml, error failed to read kubelet config file "/var/lib/ku
這個不影響,不用關係,啓動了kubernetes後就會正常
執行kubectl看到報錯 The connection to the server localhost:8080 was refused - did you specify the right host or port?
這是因爲kubernetes默認不開放http 8080訪問。
能夠在/etc/kubernetes/manifests/kube-apiserver.yaml看到開啓了https 6443訪問。 也能夠經過sudo netstat -apn | grep tcp | grep LISTEN
看到開的的端口
能夠使用sudo kubectl --kubeconfig=/etc/kubernetes/admin.conf api-versions
訪問,admin.conf中有端口以及key
備份/etc/apt/sources.list後替換爲如下內容
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
執行sudo apt update && sudo apt-get update
更新apt源。可是致使了 package xxx has no installation candidate
,使用Ubuntu官方源就OK
安裝完集羣后,生成一個pod,pod一直是pending狀態。查看pod的描述
sudo kubectl describe pod helloworld
pod描述信息
....... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 32s (x2 over 32s) default-scheduler 0/3 nodes are available: 3 node(s) had taints that the pod didn't tolerate.
執行kubectl taint nodes --all node-role.kubernetes.io/master-
,node正常使用參與調度
service沒法訪問,通查看node狀態
sudo kubectl get pod -o yaml
存儲node網絡異常狀況
...... conditions: - lastHeartbeatTime: 2019-05-21T14:39:22Z lastTransitionTime: 2019-05-21T13:08:37Z message: kubelet has sufficient disk space available reason: KubeletHasSufficientDisk status: "False" type: OutOfDisk - lastHeartbeatTime: 2019-05-21T14:39:22Z lastTransitionTime: 2019-05-21T13:08:37Z message: kubelet has sufficient memory available reason: KubeletHasSufficientMemory status: "False" type: MemoryPressure - lastHeartbeatTime: 2019-05-21T14:39:22Z lastTransitionTime: 2019-05-21T13:08:37Z message: kubelet has no disk pressure reason: KubeletHasNoDiskPressure status: "False" type: DiskPressure - lastHeartbeatTime: 2019-05-21T14:39:22Z lastTransitionTime: 2019-05-21T13:08:37Z message: kubelet has sufficient PID available reason: KubeletHasSufficientPID status: "False" type: PIDPressure - lastHeartbeatTime: 2019-05-21T14:39:22Z lastTransitionTime: 2019-05-21T13:08:37Z message: 'runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized' reason: KubeletNotReady status: "False" type: Ready ......
第一次出現問題是由於沒有安裝flannel網絡插件。
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
安裝完畢網絡插件後,提示cni config uninitialized
。
先關閉node上的kubelet; 而後使用kubeadm reset|| kubeadm join ..., 將node從新加入集羣
基於 Ubuntu 18.04 安裝部署K8s集羣 Ubuntu-18.04使用kubeadm安裝kubernetes-1.12.0 kubeadm安裝k8s集羣 apt-get 軟件源文件格式以及ubuntu 18.04更換阿里源 [cni config uninitialized解決方案](cni config uninitialized "cni config uninitialized解決方案") cni config uninitialized