環境介紹:
hostname | os | IP | note |
---|---|---|---|
node-k00 | ubuntu16.04 | 10.1.200.100 | kubernetes master |
node-k01 | ubuntu16.04 | 10.1.200.101 | kubernetes note |
node-k02 | ubuntu16.04 | 10.1.200.102 | kubernetes note |
node-k03 | ubuntu16.04 | 10.1.200.103 | kubernetes note |
1.首先在master以及node上安裝kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.7.5/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
2.安裝kubeadm (在master)
sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF'
sudo apt-get update && sudo apt-get install -y kubelet kubeadm
3.使用kubeadm初始化kubernetes (在master)
sudo kubeadm init --kubernetes-version=v1.8.0 --pod-network-cidr 10.244.0.0/16
4.複製設定檔 (在master)
mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
5.等待一段時間後,使用下列指令確認一下pod部署狀態 (在master).
kubectl get pods --all-namespaces -o wide
6.建立網路 (在master)
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
並等待一段時間後,使用下列指令確認一下pod部署狀態 (在master).
kubectl get pods --all-namespaces -o wide
7.加入 dashboard-admin, 參考來源 (在master)
cat <<EOF > dashboard-admin.yaml
{
"apiVersion": "rbac.authorization.k8s.io/v1beta1",
"kind": "ClusterRoleBinding",
"metadata": {
"name": "kubernetes-dashboard",
"labels": {
"k8s-app": "kubernetes-dashboard"
}
},
"roleRef": {
"apiGroup": "rbac.authorization.k8s.io",
"kind": "ClusterRole",
"name": "cluster-admin"
},
"subjects": [
{
"kind": "ServiceAccount",
"name": "kubernetes-dashboard",
"namespace": "kube-system"
}
]
}
EOF
kubectl create -f dashboard-admin.yaml
rm dashboard-admin.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
並等待一段時間後,使用下列指令確認一下pod部署狀態 (在master).
kubectl get pods --all-namespaces -o wide
8.建立proxy,讓瀏覽器可以開始dashboard (在master)
nohup kubectl proxy --address 0.0.0.0 --accept-hosts '.*' >/dev/null 2>&1 &
9.開啟kubenetes dashboard (在10.1.0.0/16的網域內)
http://10.1.200.100:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
10.加入Nginx Backend (在master)
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress/master/examples/deployment/nginx/default-backend.yaml
11.加入 Ingress RBAC 認證 (在master)
curl -O https://raw.githubusercontent.com/kubernetes/ingress/master/examples/rbac/nginx/nginx-ingress-controller-rbac.yml
## 修改 namespace
sed -i 's/namespace: nginx-ingress/namespace: kube-system/g' nginx-ingress-controller-rbac.yml
## 匯入yaml檔案
kubectl apply -f nginx-ingress-controller-rbac.yml
rm -r nginx-ingress-controller-rbac.yml
12.加入 Ingress Controller (在master)
curl -O https://raw.githubusercontent.com/kubernetes/ingress/master/examples/daemonset/nginx/nginx-ingress-daemonset.yaml
## 修改 namespace
sed -i 's/terminationGracePeriodSeconds/hostNetwork: true\n serviceAccountName: nginx-ingress-serviceaccount\n terminationGracePeriodSeconds/g' nginx-ingress-daemonset.yaml
## 匯入yaml檔案
kubectl apply -f nginx-ingress-daemonset.yaml
rm nginx-ingress-daemonset.yaml
kubectl get daemonset -n kube-system nginx-ingress-lb
13.加入其他的node (在master)
token=$(sudo kubeadm token list | grep authentication,signing | awk '{print $1}')
ssh 10.1.200.101 "sudo kubeadm join --token $token 10.1.200.100:6443"
ssh 10.1.200.102 "sudo kubeadm join --token $token 10.1.200.100:6443"
ssh 10.1.200.103 "sudo kubeadm join --token $token 10.1.200.100:6443"
文章短網址: https://slanla.com/__ro2uoj