K8S 集群环境搭建
K8S 集群环境搭建 系统配置修改替换阿里源wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7
K8S 集群环境搭建
系统配置修改
替换阿里源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo nyum makecache
关闭防火墙
systemctl stop firewalld & systemctl disable firewalld
关闭Swap
执行swapoff -a可临时关闭,但系统重启后恢复
编辑/etc/fstab,注释掉包含swap的那一行即可,重启后可永久关闭,如下所示:
/dev/mapper/centos-root / xfs defaults 0 0nUUID=20ca01ff-c5eb-47bc-99a0-6527b8cb246e /boot xfs defaults 0 0n# /dev/mapper/centos-swap swap
关闭SeLinux 执行:
setenforce 0
安装docker
yum -y install yum-utils # 添加 yum-config-manager 命令n nyum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.reponyum install docker-ce -y # 安装最新dockern n systemctl start docker n systemctl enable dockern ndocker run hello-world
修改或创建/etc/docker/daemon.json,加入下面的内容:
Copy
{n "exec-opts": ["native.cgroupdriver=systemd"]n}
卸载旧的版本包
yum erase docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64n
安装k8s
配置K8S的yum源
cat <<EOF > /etc/yum.repos.d/kubernetes.repon n[kubernetes]n nname=Kubernetesn nbaseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64n nenabled=1n ngpgcheck=0n nrepo_gpgcheck=0n ngpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpgn n http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpgn nEOF
安装 K8S 组件
执行以下命令安装 kubelet、kubeadm、kubectl:
yum install -y kubelet kubeadm kubectln nsystemctl enable kubelet && systemctl start kubeletn
部署 K8S 组件
由于原镜像需要翻墙,所以从国内镜像下载Docker 镜像,然后从新改名
1)Master端:
根据所需镜像名字先拉取国内资源
docker pull mirrorgooglecontainers/kube-apiserver:v1.16.2 && docker pull mirrorgooglecontainers/kube-controller-manager:v1.16.2 && docker pull mirrorgooglecontainers/kube-scheduler:v1.16.2 && docker pull mirrorgooglecontainers/kube-proxy:v1.16.2 && docker pull mirrorgooglecontainers/pause:3.1 && docker pull mirrorgooglecontainers/etcd:3.3.10 && docker pull coredns/coredns:1.3.1
修改镜像tag
docker tag mirrorgooglecontainers/kube-apiserver:v1.16.2 k8s.gcr.io/kube-apiserver:v1.16.2 && docker tag mirrorgooglecontainers/kube-controller-manager:v1.16.2 k8s.gcr.io/kube-controller-manager:v1.16.2 && docker tag mirrorgooglecontainers/kube-scheduler:v1.16.2 k8s.gcr.io/kube-scheduler:v1.16.2 && docker tag mirrorgooglecontainers/kube-proxy:v1.16.2 k8s.gcr.io/kube-proxy:v1.16.2 && docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1 && docker tag mirrorgooglecontainers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10 && docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
删除原来的镜像
docker rmi mirrorgooglecontainers/kube-apiserver:v1.16.2 && docker rmi mirrorgooglecontainers/kube-controller-manager:v1.16.2 && docker rmi mirrorgooglecontainers/kube-scheduler:v1.16.2 && docker rmi mirrorgooglecontainers/kube-proxy:v1.16.2 && docker rmi mirrorgooglecontainers/pause:3.1 && docker rmi mirrorgooglecontainers/etcd:3.3.10 && docker rmi coredns/coredns:1.3.1
2)Node端:
根据所需镜像名字先拉取国内资源
docker pull mirrorgooglecontainers/kube-proxy:v1.16.2 && docker pull mirrorgooglecontainers/pause:3.1
修改镜像tag
docker tag mirrorgooglecontainers/kube-proxy:v1.16.2 k8s.gcr.io/kube-proxy:v1.16.2 && docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1n
删除原来的镜像
docker rmi mirrorgooglecontainers/kube-proxy:v1.16.2 && docker rmi mirrorgooglecontainers/pause:3.1n
3)初始化 Master
~# kubeadm init --apiserver-advertise-address 10.9.87.0 --pod-network-cidr 10.244.0.0/16 --kubernetes-version 1.16.2
4)初始化 Node
~# kubeadm join 10.9.87.0:6443 --token a70x0p.08wolbfh169ix7du --discovery-token-ca-cert-hash sha256:e58ed8ae6bdcb65c2efa38af6f88d151d426f909d1b36e475c2eca5cbf7d3b58n
5)校验安装
~# kubectl get nodes