0. 安裝前准备工作
更换centos镜像源
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum makecache
更换docker镜像源
vi /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
systemctl restart docker.service
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 = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
5.使命令4生效
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
6.安装docker的yum源
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
7.安装docker,设置开机自启
yum makecache fast
yum install -y --setopt=obsoletes=0 \
docker-ce-18.06.1.ce-3.el7
systemctl start docker
systemctl enable docker
8.安装的kubelet、kubectl、kubeadm源
阿里云:
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
enabled=1
EOF
谷歌官方
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
9.安装kubelet、kubectl、kubeadm
yum makecache fast
yum install -y kubelet kubeadm kubectl //安装最新版本
yum install -y kubelet-1.12.3 kubeadm-1.12.3 kubectl-1.12.3 //安装指定版本
yum install kubernetes-cni.x86_64 0:0.6.0-0
10.关闭swap
swapoff -a
11.修改文件/etc/sysctl.d/k8s.conf添加vm.swappiness=0
12.kubelet开机启动
systemctl enable kubelet
systemctl start kubelet
13.拉取镜像
此时仅仅源为阿里云时需要拉镜像
docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.12.3
docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.12.3
docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.12.3
docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.12.3
docker pull mirrorgooglecontainers/pause-amd64:3.1
docker pull mirrorgooglecontainers/etcd-amd64:3.2.24
docker pull kuberneter/coredns:1.2.2
docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.12.3 k8s.gcr.io/kube-apiserver:v1.12.3
docker tag mirrorgooglecontainers/kube-controller-manager-amd64:v1.12.3 k8s.gcr.io/kube-controller-manager:v1.12.3
docker tag mirrorgooglecontainers/kube-scheduler-amd64:v1.12.3 k8s.gcr.io/kube-scheduler:v1.12.3
docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.12.3 k8s.gcr.io/kube-proxy:v1.12.3
docker tag mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/etcd-amd64:3.2.24 k8s.gcr.io/etcd:3.2.24
docker 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 reset
ifconfig cni0 down
ip link delete cni0
ifconfig flannel.1 down
ip link delete flannel.1
rm -rf /var/lib/cni/
16.初始化显示成功
a.当前为root用户
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile
b.当前为普通用户
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。