kubeadm安裝
安裝環(huán)境(vm6.5下虛擬機3臺全景,centos 7.4):
master:10.20.0.191
Node1:10.20.0.192
Node2:10.20.0.193
1.安裝虛擬機,配置網(wǎng)絡(luò)接口询刹;
2.修改主機名
hostnamectl set-hostname k8s-master
3.安裝常用工具
yum install wget -y
yum install net-tools -y
yum install vim -y
4.配置yum源環(huán)境(是用阿里云鏡像)
docker-ce
/etc/yum.repos.d目錄下
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
kubernetes
/etc/yum.repos.d目錄下
vim kubenetes.repo
[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 #開啟gpg校驗
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
enabled=1
yum repolist 檢測yum源列表
5.gpg校驗配置
下載校驗文件
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)入校驗文件
rpm --import rpm-package-key.gpg
rpm --import yum-key.gpg
6.關(guān)閉firewall莽红,修改內(nèi)核參數(shù)
systemctl disable firewalld
systemctl stop firewalld
vim /etc/sysctl.d/k8s.conf
添加如下內(nèi)容
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
執(zhí)行命令生效
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
禁用節(jié)點上的swap
swapoff -a
sysctl -p
vim /ets/fstab #去除該文件中關(guān)于swap那行
7.安裝docker-ce竭业,kubelet組件
master節(jié)點安裝
yum install docker-ce kubelet kubeadm kubectl
node節(jié)點安裝
yum install docker-ce kubelet kubeadm
8.啟動docker,kubelet
- 編輯kubelet的配置文件/etc/sysconfig/kubelet国葬,設(shè)置其忽略Swap啟用的狀態(tài)錯誤贤徒,內(nèi)容如下: KUBELET_EXTRA_ARGS=“—fail-swap-on=false” ,master以及node節(jié)點均需設(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
- 啟動docker,kubelet
systemctl enable docker kubelet
systemctl start docker
- 無代理服務(wù)背苦,可以把k8s的軟件包下載到本地安裝互捌,通過(docker load)命令加載tar包;
9.初始化master節(jié)點,node節(jié)點
master節(jié)點需要pull完成的相關(guān)鏡像
k8s.gcr.io/kube-proxy v1.13.3 98db19758ad4 2 weeks ago 80.3MB
k8s.gcr.io/kube-apiserver v1.13.3 fe242e556a99 2 weeks ago 181MB
k8s.gcr.io/kube-controller-manager v1.13.3 0482f6400933 2 weeks ago 146MB
k8s.gcr.io/kube-scheduler v1.13.3 3a6f709e97a0 2 weeks ago 79.6MB
k8s.gcr.io/coredns 1.2.6 f59dcacceff4 3 months ago 40MB
k8s.gcr.io/etcd 3.2.24 3cab8e1b9802 5 months ago 220MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 14 months ago 742kB
quay.io/coreos/flannel v0.11.0-amd64 ff281650a721 2 weeks ago 52.6MB
node節(jié)點需要pull完成的相關(guān)鏡像
k8s.gcr.io/kube-proxy v1.13.3 98db19758ad4 2 weeks ago 80.3MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 14 months ago 742kB
quay.io/coreos/flannel v0.11.0-amd64 ff281650a721 2 weeks ago 52.6MB
目前默認(rèn)版本為1.13.3
kubeadm init --help 查看啟動參數(shù) 默認(rèn)監(jiān)聽端口6443
kubeadm init --kubernetes-version=v1.13.3 --pod-network-cidr=10.244.0.0/16 service-
cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
啟動完成后會顯示join命令行剂,記得保存
根據(jù)提示完成非root用戶配置
mkdir ~/.kube
cp /etc/kubernetes/admin.conf ~/.kube/
chown $(id -u):$(id -g) $HOME/.kube/config
檢查啟動情況(nodes此時還只有master節(jié)點秕噪,未安裝flannel時候狀態(tài)不是ready)
[root@k8s-master yum.repos.d]# kubectl get componentstatus
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health": "true"}
[root@k8s-master yum.repos.d]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 137m v1.13.3
k8s-node1 Ready <none> 72m v1.13.3
k8s-node2 Ready <none> 59m v1.13.3
10.安裝flannel組件
coredns依賴flannel組件,未安裝flannel時候查看coredns的狀態(tài)為prending
[root@k8s-master yum.repos.d]# kubectl get pods -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-86c58d9df4-697md 1/1 Running 0 141m 10.244.0.2 k8s-master <none> <none>
coredns-86c58d9df4-7ppx6 1/1 Running 0 141m 10.244.0.3 k8s-master <none> <none>
etcd-k8s-master 1/1 Running 0 140m 10.20.0.191 k8s-master <none> <none>
kube-apiserver-k8s-master 1/1 Running 0 140m 10.20.0.191 k8s-master <none> <none>
kube-controller-manager-k8s-master 1/1 Running 0 140m 10.20.0.191 k8s-master <none> <none>
kube-flannel-ds-amd64-jnr54 1/1 Running 0 108m 10.20.0.191 k8s-master <none> <none>
kube-flannel-ds-amd64-n9c74 1/1 Running 0 64m 10.20.0.193 k8s-node2 <none> <none>
kube-flannel-ds-amd64-x7tj8 1/1 Running 0 77m 10.20.0.192 k8s-node1 <none> <none>
kube-proxy-8cvq4 1/1 Running 0 77m 10.20.0.192 k8s-node1 <none> <none>
kube-proxy-kc6bb 1/1 Running 0 64m 10.20.0.193 k8s-node2 <none> <none>
kube-proxy-rcfrt 1/1 Running 0 141m 10.20.0.191 k8s-master <none> <none>
kube-scheduler-k8s-master 1/1 Running 0 141m 10.20.0.191 k8s-master <none> <none>
安裝flannel
master節(jié)點
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
正常會自動pull flannel鏡像厚宰,如網(wǎng)絡(luò)不穩(wěn)定腌巾,可以手動pull
docker pull quay.io/coreos/flannel:v0.11.0-amd64
node節(jié)點在加入k8s之后會自動pull flannel鏡像,無需額外配置铲觉;
11.node節(jié)點加入k8s
kubeadm join 10.20.0.191:6443 --token qpibgq.aj47u2bq7l7w898x --discovery-token-ca-cert-hash sha256:868e795381864a9234e2a29f96cd6095831e8775a80a1f2c81319569cb876ff4 --ignore-preflight-errors=Swap
查看狀態(tài)
[root@k8s-master yum.repos.d]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 144m v1.13.3
k8s-node1 Ready <none> 79m v1.13.3
k8s-node2 Ready <none> 66m v1.13.3