环境:
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
安装完成!!!