環境:
CentOS Linux release 7.4.1708
Docker version 17.03.0-ce
hosts: ##一定要定義host,負責在添加節點的時候會報錯
10.22.60.150 master
10.22.60.151 node01
一、基礎環境準備(master和node)
1、安裝依賴軟件:(master和node)
$ sudo yum install ebtables ethtool iproute iptables socat util-linux wget vim -y
2、安裝docker17.0.3:(master和node)
$ sudo wget -O - https://raw.githubusercontent.com/cherryleo/scripts/master/centos7-install-docker.sh | sudo sh
3、配置環境:(master和node)
$ sudo swapoff -a # 關閉swap分區
$ sudo systemctl disable firewalld #關閉防火牆
$ sudo systemctl stop firewalld
$ sudo sysctl net.bridge.bridge-nf-call-iptables=1 # 調整內核參數
$ export KUBERNETES_VERSION="1.10.0" # 定義版本變量,後面會用到這個變量
4、安裝k8s:(master和node)
$ wget -O - https://raw.githubusercontent.com/cherryleo/cherryleo/master/install-k8s-packages.sh | bash
檢查docker安裝
$ sudo docker info | grep -i cgroup
Cgroup Driver: cgroupfs
編輯kubeadm配置
$ vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
Environment="KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10 --cluster-domain=cluster.local"
Environment="KUBELET_AUTHZ_ARGS=--authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt"
# Value should match Docker daemon settings.
# Defaults are "cgroupfs" for Debian/Ubuntu/OpenSUSE and "systemd" for Fedora/CentOS/RHEL
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"
Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=0"
Environment="KUBELET_CERTIFICATE_ARGS=--rotate-certificates=true"
Environment="KUBE_PAUSE=--pod-infra-container-image=ccr.ccs.tencentyun.com/cherryleo/pause-amd64:3.0"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_AUTHZ_ARGS $KUBELET_CGROUP_ARGS $KUBELET_CADVISOR_ARGS $KUBELET_CERTIFICATE_ARGS $KUBE_PAUSE $KUBELET_EXTRA_ARGS
重啓服務
$ sudo systemctl daemon-reload
$ sudo systemctl restart kubelet
二、配置服務及安裝插件(master)
1、創建模板文件(master)
$ cat >config.yaml <<EOF
apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
api:
advertiseAddress: 10.22.60.150
networking:
podSubnet: 10.244.0.0/16
apiServerCertSANs:
- 10.22.60.150
imageRepository: ccr.ccs.tencentyun.com/cherryleo
kubernetesVersion: v${KUBERNETES_VERSION}
EOF
2、創建服務(master)
$ sudo -E kubeadm init --config=config.yaml
...
...
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join 10.22.60.150:6443 --token hwrv1q.z1iewykhh54whepp --discovery-token-ca-cert-hash sha256:03df785551b9c7474874f828bf265e24865f6e16f00e0ad4e0436c8e1cf472b1 # 此行信息爲node添加的信息,請保存
3、創建kubectl配置文件(master)
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
4、 網絡插件安裝,此處flannel網絡(master)
$ kubectl apply -f https://raw.githubusercontent.com/cherryleo/k8s-apps/master/k8s-flannel/flannel.yaml
5、UI dashboard安裝(master)
$ kubectl apply -f https://raw.githubusercontent.com/cherryleo/k8s-apps/master/k8s-dashboard/kubernetes-dashboard.yaml
6、 創建admin用戶(master)
$ kubectl apply -f https://raw.githubusercontent.com/cherryleo/k8s-apps/master/k8s-dashboard/admin-user.yaml
登錄測試:
訪問https://10.22.60.150:30080進入登陸頁面(使用火狐瀏覽器)
獲取token,使用token登錄
$ kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
三、Node節點添加(node)
## 首先在node節點中,將“基礎環境準備”部署完成
1、 添加node節點
$ kubeadm join 10.22.60.150:6443 --token hwrv1q.z1iewykhh54whepp --discovery-token-ca-cert-hash sha256:03df785551b9c7474874f828bf265e24865f6e16f00e0ad4e0436c8e1cf472b1
2、在master查看節點是否添加
$ kubectl get node
NAME STATUS ROLES AGE VERSION
master Ready master 15d v1.10.0
node01 Ready <none> 15d v1.10.0
安裝完成!!!