kubeadm部署K8S集群v1.16.3
本次先更新kubeadm快速安装K8S,二进制安装上次没写文档,后续更新,此次最新的版本是V1.16.3
selinux=disabled
swapoff -a
1、关闭防火墙、关闭selinux、关闭swapoff -a
systemctl stop firewalldselinux=disabled
swapoff -a
2、修改系统参数
创建 /etc/sysctl.d/k8s.conf 文件cat > /etc/sysctl.d/k8s.conf << EOF net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF
生效配置文件
modprobe br_netfilter sysctl -p /etc/sysctl.d/k8s.conf
修改hosts
cat > /etc/hosts << EOF master 192.168.200.221 node1 192.168.200.222 node2 192.168.200.223 EOF
3、安装docker
1)常用方法
a、配置yum源
阿里镜像源
a、配置yum源
阿里镜像源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Docker官方镜像源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
b、安装docker
显示docker-ce所有可安装版本: yum list docker-ce --showduplicates | sort -r 安装指定docker版本 yum install docker-ce-18.06.1.ce-3.el7 -y # 修改docker配置 vi /lib/systemd/system/docker.service 找到这行,王、后面加上存储目录,例如这里是 --graph /apps/docker (此处也可以另外建一个文件去指定,详细参考下面方法) ExecStart=/usr/bin/docker --graph /apps/docker 启动docker并设置docker开机启动 systemctl enable docker systemctl start docker
2)本地rpm包安装
a)下载地址
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
17版本请把docker-ce-selinux也一起下载
b、创建挂在目录以及阿里源的文件
a)下载地址
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
17版本请把docker-ce-selinux也一起下载
b、创建挂在目录以及阿里源的文件
mkdir -p /data/docker-root mkdir -p /etc/docker touch /etc/docker/daemon.json chmod 700 /etc/docker/daemon.json cat > /etc/docker/daemon.json << EOF { "graph":"/data/docker-root", "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com"] } EOF 这里可能会涉及到要求docker用systemd,我这个版本没有用到,用到反而报错,如果需要用到,就在上面文件加入这句 "exec-opts":["native.cgroupdriver=systemd"],
c、安装docker
yum localinstall ./docker* -y 启动docker并设置docker开机启动 systemctl enable docker systemctl start docker
3)二进制安装
a)下载地址
二进制包下载地址:https://download.docker.com/linux/static/stable/x86_64/
b)解压安装
a)下载地址
二进制包下载地址:https://download.docker.com/linux/static/stable/x86_64/
b)解压安装
tar zxvf docker-18.09.6.tgz mv docker/* /usr/bin mkdir /etc/docker mv daemon.json /etc/docker mv docker.service /usr/lib/systemd/system 启动docker并设置docker开机启动 systemctl start docker systemctl enable docker c)涉及到的daemon.json和docker.service的文件内容 为了配置docker的目录和docker改为systemd以及阿里源 "exec-opts":["native.cgroupdriver=systemd"], cat > /etc/docker/daemon.json << EOF { "graph":"/data/docker-root", "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com"] } EOF 为了设置命令启动的 cat > /usr/lib/systemd/system/docker.service << EOF [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network.target firewalld.service [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process [Install] WantedBy=multi-user.target EOF
4、安装kubeadm、kubelet、kubectl(每个节点)
1)配置可用的国内yum源用于安装
1)配置可用的国内yum源用于安装
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=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
--官网的yum源如下
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 exclude=kube* EOF
2)安装kubeadm、kubelet、kubectl
查看相关版本,然后来选择 yum list kubelet --showduplicates | sort -r yum list kubeadm --showduplicates | sort -r yum list kubectl --showduplicates | sort -r 安装,默认最新版 yum install -y kubelet kubeadm kubectl 指定版本 yum install -y kubeadm-1.16.3-0 kubelet-1.16.3-0 kubectl-1.16.3-0 安装 kubeadm 时候会默认安装 kubectl ,所以不需要单独安装kubectl systemctl daemon-reload && systemctl enable kubelet && systemctl start kubelet
5、启动K8S集群
1)kubeadm init
kubeadm init --apiserver-advertise-address=192.168.200.221 --image-repository registry.aliyuncs.com/google_containers --ignore-preflight-errors=all --kubernetes-version v1.16.3 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16
kubernetes-version 后面的值通过 kubelet --version 查看
里面需要下载多个镜像,所以这指定镜像源
最后成功会有如下信息需要在主节点创建
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config 如果时root用户可以直接export export KUBECONFIG=/etc/kubernetes/admin.conf 然后在每个node节点创建 kubeadm join 192.168.200.221:6443 --token jc8adl.4esmazfzlw6uee9k \ --discovery-token-ca-cert-hash sha256:6655ce24a5d0b4aa8169ee6d66bd1220e42b05a4a792a947f8fe8c1819b43cb3 若有部分错,请加上这个参数--ignore-preflight-errors=all
6、最后得到的node是notready
因为还没有安装网络插件
因为还没有安装网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
--我的电脑开三台虚拟机就卡的不行了,所以后续的使用没有去操作--