kubeadm安裝k8s集群kubeadm安裝Kubernetes V1.16.2集群詳細(xì)文檔kubeadm安裝
安裝環(huán)境(vm15.0.4下虛擬機(jī)3臺(tái)腊尚,centos 7.6):
Master:192.168.10.100
Node1:192.168.10.101
Node2:192.168.10.102
1:安裝虛擬機(jī),配置網(wǎng)絡(luò)接口是己,使虛擬機(jī)訪問訪問正常
2:修改主機(jī)名
hostnamectl set-hostname kube-master
hostnamectl set-hostname kube-node1
hostnamectl set-hostname kube-node2
3:配置主機(jī)映射
[root@kube-master ~]# more /etc/hosts
127.0.0.1? localhost localhost.localdomain localhost4 localhost4.localdomain4
::1? ? ? ? localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.100? kube-master
192.168.10.101? kube-node1
192.168.10.102? kube-node2
4:kube-master上配置免密鑰登陸
ssh-keygen #一路回車即可
ssh-copy-id? kube-master
ssh-copy-id? kube-node1
ssh-copy-id? kube-node2
5:三臺(tái)主機(jī)關(guān)閉防火墻雳攘,selinux带兜,配置系統(tǒng)內(nèi)核
#關(guān)閉防火墻
systemctl stop firewalld
systemctl disable firewalld
#關(guān)閉selinux
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/sysconfig/selinux
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config
#配置系統(tǒng)內(nèi)核
echo 1 >/proc/sys/net/bridge/bridge-nf-call-iptables
echo 1 >/proc/sys/net/bridge/bridge-nf-call-ip6tables
6:配置yum源環(huán)境(使用阿里云鏡像)三臺(tái)主機(jī)配置
#docker-ce yum源配置
cd /etc/yum.repos.d/
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# kubernetes yum源配置
cd? /etc/yum.repos.d
[root@k8s-master yum.repos.d]# cat kubenetes.repo
[kubernetes]
name=Kubernetes Repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1? ?
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
enabled=1
yum repolist 檢測yum源列表
7:gpg校驗(yàn)配置,三臺(tái)主機(jī)配置
下載校驗(yàn)文件
wget https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
wget https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
導(dǎo)入校驗(yàn)文件
rpm --import rpm-package-key.gpg
rpm --import yum-key.gpg
8:安裝docker-ce吨灭,kubeadm組件
master節(jié)點(diǎn)安裝
yum install docker-ce kubelet kubeadm kubectl
node節(jié)點(diǎn)安裝
yum install docker-ce kubelet kubeadm
9:啟動(dòng)docker刚照,kubelet
編輯kubelet的配置文件/etc/sysconfig/kubelet,設(shè)置其忽略Swap啟用的狀態(tài)錯(cuò)誤喧兄,內(nèi)容如下: KUBELET_EXTRA_ARGS="--fail-swap-on=false"? master以及node節(jié)點(diǎn)均需設(shè)置无畔;
[root@k8s-master yum.repos.d]# cat /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
google的鏡像倉庫k8s.grc.io國內(nèi)無法訪問,如有代理服務(wù)器吠冤,則編輯docker.service文件浑彰,添加代理服務(wù)器
vim /usr/lib/systemd/system/docker.service
添加如下內(nèi)容
Environment="HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/"
保存退出,從新加載配置文件拯辙,重啟docker
systemctl daemon-reload
systemctl restart docker
設(shè)置docker郭变,kubelet開機(jī)自啟動(dòng),開啟docker
systemctl enable docker kubelet
systemctl start docker
無代理服務(wù)涯保,可以把k8s的軟件包下載到本地安裝诉濒,通過(docker load)命令加載tar包;
10:初始化master節(jié)點(diǎn),node節(jié)點(diǎn)
master節(jié)點(diǎn)需要pull完成的相關(guān)鏡像
k8s.gcr.io/kube-proxy? ? ? ? ? ? ? ? v1.16.2? ? ? ? ? ? 8454cbe08dc9? ? ? ? 2 days ago? ? ? ? ? 86.1MB
k8s.gcr.io/kube-scheduler? ? ? ? ? ? v1.16.2? ? ? ? ? ? ebac1ae204a2? ? ? ? 2 days ago? ? ? ? ? 87.3MB
k8s.gcr.io/kube-controller-manager? v1.16.2? ? ? ? ? ? 6e4bffa46d70? ? ? ? 2 days ago? ? ? ? ? 163MB
k8s.gcr.io/kube-apiserver? ? ? ? ? ? v1.16.2? ? ? ? ? ? c2c9a0406787? ? ? ? 2 days ago? ? ? ? ? 217MB
k8s.gcr.io/etcd? ? ? ? ? ? ? ? ? ? ? 3.3.15-0? ? ? ? ? ? b2756210eeab? ? ? ? 6 weeks ago? ? ? ? 247MB
k8s.gcr.io/coredns? ? ? ? ? ? ? ? ? 1.6.2? ? ? ? ? ? ? bf261d157914? ? ? ? 2 months ago? ? ? ? 44.1MB
quay.io/coreos/flannel? ? ? ? ? ? ? v0.11.0-amd64? ? ? ff281650a721? ? ? ? 8 months ago? ? ? ? 52.6MB
k8s.gcr.io/pause? ? ? ? ? ? ? ? ? ? 3.1? ? ? ? ? ? ? ? da86e6ba6ca1? ? ? ? 22 months ago? ? ? 742kB
node節(jié)點(diǎn)需要pull完成的相關(guān)鏡像
k8s.gcr.io/kube-proxy? ? v1.16.2? ? ? ? ? ? 8454cbe08dc9? ? ? ? 2 days ago? ? ? ? ? 86.1MB
quay.io/coreos/flannel? ? v0.11.0-amd64? ? ? ff281650a721? ? ? ? 8 months ago? ? ? ? 52.6MB
k8s.gcr.io/pause? ? ? ? ? 3.1? ? ? ? ? ? ? ? da86e6ba6ca1? ? ? ? 22 months ago? ? ? 742kB
目前默認(rèn)版本為1.16.2
kubeadm init --help 查看啟動(dòng)參數(shù) 默認(rèn)監(jiān)聽端口6443
kubeadm init --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
啟動(dòng)完成后會(huì)顯示join命令夕春,記得保存
根據(jù)提示完成非root用戶配置
mkdir ~/.kube
cp /etc/kubernetes/admin.conf ~/.kube/
chown $(id -u):$(id -g) $HOME/.kube/config
檢查啟動(dòng)情況(nodes此時(shí)還只有master節(jié)點(diǎn)未荒,未安裝flannel時(shí)候狀態(tài)不是ready)
[root@kube-master yum.repos.d]# kubectl get componentstatus
NAME? ? ? ? ? ? ? ? STATUS? ? MESSAGE? ? ? ? ? ? ? ERROR
scheduler? ? ? ? ? ? Healthy? ok? ? ? ? ? ? ? ? ?
controller-manager? Healthy? ok? ? ? ? ? ? ? ? ?
etcd-0? ? ? ? ? ? ? Healthy? {"health": "true"}?
[root@kube-master ~]# kubectl get nodes
NAME? ? ? ? ? STATUS? ROLES? ? AGE? VERSION
kube-master? Ready? ? master? 24h? v1.16.2
kube-node1? ? Ready? ? <none>? 23h? v1.16.2
kube-node2? ? Ready? ? <none>? 23h? v1.16.2
11:安裝flannel組件
coredns依賴flannel組件,未安裝flannel時(shí)候查看coredns的狀態(tài)為prending
[root@kube-master ~]# kubectl get pods -n kube-system -o wide
NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? READY? STATUS? ? RESTARTS? AGE? IP? ? ? ? ? ? ? NODE? ? ? ? ? NOMINATED NODE? READINESS GATES
coredns-5644d7b6d9-lt5kp? ? ? ? ? ? ? 1/1? ? Running? 2? ? ? ? ? 24h? 10.244.0.7? ? ? kube-master? <none>? ? ? ? ? <none>
coredns-5644d7b6d9-nblnl? ? ? ? ? ? ? 1/1? ? Running? 2? ? ? ? ? 24h? 10.244.0.6? ? ? kube-master? <none>? ? ? ? ? <none>
etcd-kube-master? ? ? ? ? ? ? ? ? ? ? 1/1? ? Running? 2? ? ? ? ? 24h? 192.168.10.100? kube-master? <none>? ? ? ? ? <none>
kube-apiserver-kube-master? ? ? ? ? ? 1/1? ? Running? 2? ? ? ? ? 24h? 192.168.10.100? kube-master? <none>? ? ? ? ? <none>
kube-controller-manager-kube-master? 1/1? ? Running? 2? ? ? ? ? 24h? 192.168.10.100? kube-master? <none>? ? ? ? ? <none>
kube-proxy-5c5km? ? ? ? ? ? ? ? ? ? ? 1/1? ? Running? 2? ? ? ? ? 23h? 192.168.10.101? kube-node1? ? <none>? ? ? ? ? <none>
kube-proxy-j56kp? ? ? ? ? ? ? ? ? ? ? 1/1? ? Running? 2? ? ? ? ? 23h? 192.168.10.102? kube-node2? ? <none>? ? ? ? ? <none>
kube-proxy-pvlzt? ? ? ? ? ? ? ? ? ? ? 1/1? ? Running? 2? ? ? ? ? 24h? 192.168.10.100? kube-master? <none>? ? ? ? ? <none>
kube-scheduler-kube-master? ? ? ? ? ? 1/1? ? Running? 2? ? ? ? ? 24h? 192.168.10.100? kube-master? <none>? ? ? ? ? <none>
安裝flannel
master節(jié)點(diǎn)
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
正常會(huì)自動(dòng)pull flannel鏡像撇他,如網(wǎng)絡(luò)不穩(wěn)定茄猫,可以手動(dòng)pull
docker pull quay.io/coreos/flannel:v0.11.0-amd64
node節(jié)點(diǎn)在加入k8s之后會(huì)自動(dòng)pull flannel鏡像,無需額外配置困肩;
12:node節(jié)點(diǎn)加入k8s
kubeadm join 192.168.10.100:6443 --token 5zx03y.ixb80qum7ktmu1mk --discovery-token-ca-cert-hash sha256:7b2a69f18281cb245a417f53dbd18076583556adbfcba29a70858e780300c3c7 --ignore-preflight-errors=Swap
查看狀態(tài)
[root@kube-master ~]# kubectl get nodes
NAME? ? ? ? ? STATUS? ROLES? ? AGE? VERSION
kube-master? Ready? ? master? 24h? v1.16.2
kube-node1? ? Ready? ? <none>? 23h? v1.16.2
kube-node2? ? Ready? ? <none>? 23h? v1.16.2
13:安裝kubectl補(bǔ)全命令
yum install bash-completion
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
14:可能碰到的問題划纽,如果受用kubectl命令報(bào)連接不上8080端口,使用下面配置
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile