一胆绊、準(zhǔn)備環(huán)境
所有節(jié)點(diǎn)操作:
1.配置好各節(jié)點(diǎn)hosts文件
2.關(guān)閉系統(tǒng)防火墻
3.關(guān)閉Selinux
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
4.關(guān)閉swap
5.在/etc/sysctl.conf中添加以下配置
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
6.配置yum源
docker yum源
cat >> /etc/yum.repos.d/docker.repo <<EOF
[docker-repo]
name=Docker Repository
baseurl=http://mirrors.aliyun.com/docker-engine/yum/repo/main/centos/7
enabled=1
gpgcheck=0
EOF
kubernetes yum源
cat >> /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF
yum clean all
yum makecache
二薇宠、安裝docker憨栽、kubeadm等
所有節(jié)點(diǎn)操作:
yum install -y docker --disableexcludes=docker-repo
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet
三浓领、kubeadm初始化集群
在master上操作:
kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --kubernetes-version=v1.13.0
輸出應(yīng)如下所示:
注意:請(qǐng)保存輸出中的 kubeadm join …………一行命令
要使kubectl為非root用戶工作反镇,請(qǐng)運(yùn)行以下命令犯戏,這些命令也是kubeadm init輸出的一部分:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
或者送火,如果是root用戶,則可以運(yùn)行:
export KUBECONFIG=/etc/kubernetes/admin.conf
四先匪、安裝flannel網(wǎng)絡(luò)
在master上操作:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
執(zhí)行 kubectl get pod -n kube-system 查看pod狀態(tài)种吸,等待所有pod處于running狀態(tài)即可。
五呀非、添加計(jì)算節(jié)點(diǎn)
在計(jì)算節(jié)點(diǎn)上操作:
執(zhí)行第三步中保存的 kubeadm join …………命令
在master上查看node添加狀態(tài):kubectl get nodes
六坚俗、部署dashboard
在master上操作:
1.下載yaml文件
wget
https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
2.更改yaml'中的image地址
將kubernetes-dashboard.yaml中的鏡像地址改為
registry.cn-qingdao.aliyuncs.com/wangxiaoke/kubernetes-dashboard-amd64:v1.10.0
3.安裝
kubectl create -f kubernetes-dashboard.yaml
查看dashboard的POD是否正常啟動(dòng),如果正常說明安裝成功
[root@node1 ~]# kubectl get pods --namespace=kube-system
NAME READY STATUS RESTARTS AGE
coredns-576cbf47c7-kg8s9 1/1 Running 0 29h
coredns-576cbf47c7-st599 1/1 Running 0 29h
etcd-node1.ztpt.com 1/1 Running 0 29h
kube-apiserver-node1.ztpt.com 1/1 Running 0 29h
kube-controller-manager-node1.ztpt.com 1/1 Running 1 29h
kube-flannel-ds-amd64-79x9h 1/1 Running 0 27h
kube-flannel-ds-amd64-f9fls 1/1 Running 0 26h
kube-flannel-ds-amd64-q7kvx 1/1 Running 0 29h
kube-proxy-242zg 1/1 Running 0 27h
kube-proxy-5ntm5 1/1 Running 0 29h
kube-proxy-6pbrv 1/1 Running 0 26h
kube-scheduler-node1.ztpt.com 1/1 Running 1 29h
kubernetes-dashboard-77fd78f978-wzqjq 1/1 Running 0 5m7s
4岸裙、配置外網(wǎng)訪問
修改service配置猖败,將type: ClusterIP改成NodePort
kubectl edit service kubernetes-dashboard --namespace=kube-system
查看外網(wǎng)暴露端口
[root@node1 ~]# kubectl get service --namespace=kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 47h
kubernetes-dashboard NodePort 10.101.221.220 <none> 443:32240/TCP 17h
5、創(chuàng)建dashboard admin-token
創(chuàng)建admin-token.yaml文件降允,文件內(nèi)容如下:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: admin
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: admin
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
創(chuàng)建用戶
kubectl create -f admin-token.yaml
獲取登陸token
kubectl describe secret/$(kubectl get secret -nkube-system |grep admin|awk '{print $1}') -nkube-system
6.通過瀏覽器登陸dashboard
https://節(jié)點(diǎn)IP:bashboard暴露端口
認(rèn)證方式選擇口令恩闻,輸入剛才獲取到的token,即可登陸成功剧董。
進(jìn)入后就會(huì)看到如下界面