系統設置
CentOS Linux release 7.6.1810 (Core)
設置本地解析
vim /etc/hosts 172.16.227.40 k8s-master
關閉及禁用防火牆
systemctl disable firewalld
systemctl stop firewalld
關閉selinux
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
設置啟動參數
cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system
安裝docker,kubeadm, kubelet and kubectl
安裝docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-18.06.3.ce-3.el7(不能安裝默認版本1.13.1,默認版本在容器中無法執行docker命令)
報錯原因查看:https://blog.csdn.net/Roger0622/article/details/108719751
systemctl start docker systemctl enable docker
kubeadm, kubelet and kubectl
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet
# 添加--image-repository參數,默認鏡像下載會失敗,
kubernetes-version與上面安裝的kubelet版本對應一樣
只有master節點需要執行,node節點只要安裝docker與kubelet,kubeadm,kubelet就可以
kubeadm init --kubernetes-version=???. --pod-network-cidr=10.244.0.0/16 --image-repository registry.aliyuncs.com/google_containers
設置kubectl命令
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
安裝pod network
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
執行上面命令出錯時提示如下:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
解決辦法:
配置kubenetes的flannel網絡的時候,出現以下報錯
The connection to the server localhost:8080 was refused - did you specify the right host or port?
原因:kubenetes master沒有與本機綁定,集群初始化的時候沒有設置
解決辦法:執行以下命令 export KUBECONFIG=/etc/kubernetes/admin.conf
/etc/kubernetes/admin.conf這個文件主要是集群初始化的時候用來傳遞參數的
這樣默認安裝好只有一個master節點
要想在主節點運行pods,還需要
5.0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.
解決方法是安裝flannel
有時候一個pod創建之后一直是pending,沒有日志,也沒有pull鏡像,describe的時候發現里面有一句話: 1 node(s) had taints that the pod didn't tolerate.
直譯意思是節點有了污點無法容忍,執行 kubectl get no -o yaml | grep taint -A 5
之后發現該節點是不可調度的。這是因為kubernetes出於安全考慮默認情況下無法在master節點上部署pod,於是用下面方法解決:
kubectl taint nodes --all node-role.kubernetes.io/master-
新節點加入k8s集群
重復以上步驟,安裝docker kubelet kubeadm kubectl
注意,node節點的kubelet這些版本要與master節點的版本相同
注意:node節點加入時要確保kubelet的cgroups與docker的cgroups一樣,當執行kubeadm join提示warning時,
[WARNING IsDockerSystemdCheck]: detected “cgroupfs“ as the Docker cgroup driver. Th
加入不了節點,會一直提示kubelet不健康,解決辦法如下:
https://blog.csdn.net/zhangbaoxiang/article/details/107422299
不用安裝kube-flannel.yml,因為node節點加入集群后,會自動拉鏡像安裝
注意,k8s的master通過init初始化后,生成的token會24小時后失效,要重新生成
https://blog.csdn.net/wo18237095579/article/details/89884369
https://www.cnblogs.com/histyle/p/10897163.html