公共配置
1.更新操作系统
代码语言:javascript复制yum -y update
reboot
2.更改hosts
代码语言:javascript复制192.168.172.132 node01.example.com
192.168.172.133 node02.example.com
3.免密登录
代码语言:javascript复制ssh-keygen
ssh-copy-id node01.example.com
ssh-copy-id node02.example.com
scp /etc/hosts node02.example.com:/etc
4.关闭防火墙
代码语言:javascript复制systemctl stop firewalld && systemctl disable firewalld
5.关闭SELINUX
代码语言:javascript复制sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
#关闭swap
swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab
6.开启IPV4转发
代码语言:javascript复制cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
7.配置yum源
代码语言:javascript复制cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
代码语言:javascript复制wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
8.安装
代码语言:javascript复制yum install -y docker-ce-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker
docker version
yum install -y kubelet kubeadm kubectl
安装Master
代码语言:javascript复制kubeadm init --kubernetes-version=1.15.3
--apiserver-advertise-address=192.168.172.132
--image-repository registry.aliyuncs.com/google_containers
--service-cidr=10.1.0.0/16
--pod-network-cidr=10.244.0.0/16
systemctl start kubelet && systemctl enable kubelet
mkdir -p /root/.kube
cp /etc/kubernetes/admin.conf /root/.kube/config
kubectl get nodes
#检查对应版本
https://quay.io/repository/coreos/flannel
docker pull quay.io/coreos/flannel:v0.11.0-amd64
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get nodes
安装node
代码语言:javascript复制kubeadm join 192.168.172.132:6443 --token pk96e8.6irwnsmmf8kt8ncz --discovery-token-ca-cert-hash sha2
56:dfb7749305372a51578578983ba628453732aa7655bdd763f43f707359e0d88d
安装Dashboard
代码语言:javascript复制wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
#更改内容
image: registry.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
type: NodePort
docker pull registry.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
kubectl create -f kubernetes-dashboard.yaml
kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
参考文档:https://mp.weixin.qq.com/s/vnriX2bTtnkv8i2UpLeNnA