Centos7安装kubernetes k8s v1.16.0 集群国内环境
程序员文章站
2022-03-07 11:30:30
...
是参考这篇博客安装成功的:https://www.jianshu.com/p/25c01cae990c
在主节点spark1中安装k8s
$ ssh [email protected]
[[email protected] ~]# yum -y install vim*
[[email protected] ~]# yum -y install wget
[[email protected] ~]# systemctl disable firewalld
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# setenforce 0
[[email protected] ~]# sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux
[[email protected] ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[[email protected] ~]# swapoff -a
[[email protected] ~]# sed -i 's/.*swap.*/#&/' /etc/fstab
[[email protected] ~]# cat <<EOF > /etc/sysctl.d/k8s.conf
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> EOF
[[email protected] ~]# sysctl --system
[[email protected] ~]# 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
[[email protected] ~]# yum install -y kubeadm-1.16.0-0 kubelet-1.16.0-0
# 启动kubelet服务
[[email protected] ~]# systemctl enable kubelet && systemctl start kubelet
[[email protected] ~]# mkdir -p $HOME/.kube
[[email protected] ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[[email protected] ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
[[email protected] ~]# kubeadm token create --print-join-command
kubeadm join 192.168.0.108:6443 --token zfjsmj.fdce6hprdjdjeq5i --discovery-token-ca-cert-hash sha256:b0bf433dcbc9a89bb5c81e6fecb9e5b83fadc1f8c6e8a78d848359d877a1b1a1
[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
spark1 NotReady master 6m14s v1.16.0
[[email protected] ~]# wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# 这个yml配置文件中配置了一个国内无法访问的地址(quay.io),需要将其改为国内可以访问的地址(quay-mirror.qiniu.com)
[[email protected] ~]# vi kube-flannel.yml
[[email protected] ~]# kubectl apply -f kube-flannel.yml
如果出现了这个报错,我用的方法是删除 kube-flannel.yml重新下载wget一份,然后再将quay.io全部替换成quay-mirror.qiniu.com
error: error validating "kube-flannel.yml": error validating data: apiVersion not set; if you choose to ignore these errors, turn validation off with --validate=false
[[email protected] ~]# kubectl apply -f kube-flannel.yml
[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
spark1 Ready master 58m v1.16.0
spark2 Ready <none> 43m v1.16.0
[[email protected] ~]# kubeadm token create --print-join-command
kubeadm join 192.168.0.108:6443 --token m2q1y5.dmujivf7q7gbn8bx --discovery-token-ca-cert-hash sha256:b0bf433dcbc9a89bb5c81e6fecb9e5b83fadc1f8c6e8a78d848359d877a1b1a1
[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
spark1 Ready master 76m v1.16.0
spark2 Ready <none> 60m v1.16.0
spark3 Ready <none> 103s v1.16.0
在从节点spark2中安装k8s
# 安装编辑器
yum -y install vim*
# 安装docker所需的工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# 配置阿里云的docker源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 指定安装这个版本的docker-ce
yum install -y docker-ce-18.09.9-3.el7
# 启动docker
systemctl enable docker && systemctl start docker
# 关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
# 关闭selinux
# 临时禁用selinux
setenforce 0
# 永久关闭 修改/etc/sysconfig/selinux文件设置
sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
# 禁用交换分区
swapoff -a
# 永久禁用,打开/etc/fstab注释掉swap那一行。
sed -i 's/.*swap.*/#&/' /etc/fstab
# 修改内核参数
cat <<EOF > /etc/sysctl.d/k8s.conf
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> EOF
sysctl --system
# 执行配置k8s阿里云源
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
# 安装kubeadm、kubectl、kubelet
yum install -y kubeadm-1.16.0-0 kubelet-1.16.0-0
# 启动kubelet服务
systemctl enable kubelet && systemctl start kubelet
# 将节点加入集群
[[email protected] ~]# kubeadm join 192.168.0.108:6443 --token 1dkzee.d1rtadqabn299nmf --discovery-token-ca-cert-hash sha256:b0bf433dcbc9a89bb5c81e6fecb9e5b83fadc1f8c6e8a78d848359d877a1b1a1
在从节点spark3中安装k8s
# 安装编辑器
yum -y install vim*
# 安装docker所需的工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# 配置阿里云的docker源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 指定安装这个版本的docker-ce
yum install -y docker-ce-18.09.9-3.el7
# 启动docker
systemctl enable docker && systemctl start docker
# 关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
# 关闭selinux
# 临时禁用selinux
setenforce 0
# 永久关闭 修改/etc/sysconfig/selinux文件设置
sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
# 禁用交换分区
swapoff -a
# 永久禁用,打开/etc/fstab注释掉swap那一行。
sed -i 's/.*swap.*/#&/' /etc/fstab
# 修改内核参数
cat <<EOF > /etc/sysctl.d/k8s.conf
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> EOF
sysctl --system
# 执行配置k8s阿里云源
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
# 安装kubeadm、kubectl、kubelet
yum install -y kubeadm-1.16.0-0 kubelet-1.16.0-0
# 启动kubelet服务
systemctl enable kubelet && systemctl start kubelet
# 将节点加入集群
kubeadm join 192.168.0.108:6443 --token m2q1y5.dmujivf7q7gbn8bx --discovery-token-ca-cert-hash sha256:b0bf433dcbc9a89bb5c81e6fecb9e5b83fadc1f8c6e8a78d848359d877a1b1a1