1.关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
2.禁用selinux
setenforce 0
3.确认selinux是否修改为disabled
vi /etc/selinux/config
4.创建/etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1net.ipv4.ip_forward = 1
5.使命令4生效
modprobe br_netfiltersysctl -p /etc/sysctl.d/k8s.conf
6.安装docker的yum源
yum install -y yum-utils device-mapper-persistent-data lvm2yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
7.安装docker,设置开机自启
yum makecache fastyum install -y --setopt=obsoletes=0 \ docker-ce-18.06.1.ce-3.el7systemctl start dockersystemctl enable docker
8.安装的kubelet、kubectl、kubeadm源
阿里云:
cat </etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/gpgcheck=0gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpgenabled=1EOF
谷歌官方
cat </etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64enabled=1gpgcheck=1repo_gpgcheck=1gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpgEOF
9.安装kubelet、kubectl、kubeadm
yum makecache fastyum install -y kubelet kubeadm kubectl //安装最新版本yum install -y kubelet-1.12.3 kubeadm-1.12.3 kubectl-1.12.3 //安装指定版本
10.关闭swap
swapoff -a
11.修改文件/etc/sysctl.d/k8s.conf添加vm.swappiness=0
12.kubelet开机启动
systemctl enable kubeletsystemctl start kubelet
13.拉取镜像
此时仅仅源为阿里云时需要拉镜像
docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.12.3docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.12.3docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.12.3docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.12.3docker pull mirrorgooglecontainers/pause-amd64:3.1docker pull mirrorgooglecontainers/etcd-amd64:3.2.24docker pull kuberneter/coredns:1.2.2docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.12.3 k8s.gcr.io/kube-apiserver:v1.12.3docker tag mirrorgooglecontainers/kube-controller-manager-amd64:v1.12.3 k8s.gcr.io/kube-controller-manager:v1.12.3docker tag mirrorgooglecontainers/kube-scheduler-amd64:v1.12.3 k8s.gcr.io/kube-scheduler:v1.12.3docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.12.3 k8s.gcr.io/kube-proxy:v1.12.3docker tag mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause:3.1docker tag mirrorgooglecontainers/etcd-amd64:3.2.24 k8s.gcr.io/etcd:3.2.24docker tag kuberneter/coredns:1.2.2 k8s.gcr.io/coredns:1.2.2
14.初始化集群
kubeadm init --kubernetes-version=1.12.3 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=140.143.0.194
15.部署集群失败
kubeadm resetifconfig cni0 downip link delete cni0ifconfig flannel.1 downip link delete flannel.1rm -rf /var/lib/cni/
16.初始化显示成功
a.当前为root用户
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profilesource ~/.bash_profile
b.当前为普通用户
mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config