centos8上部署k8s

Posted 数据库平台优化

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos8上部署k8s相关的知识,希望对你有一定的参考价值。


操作系统版本

cat /etc/redhat-releaseCentOS Linux release 8.0.1905 (Core)

主机配置


192.168.2.201 

k8smaster

192.168.2.211 

k8snode1

192.168.2.212 

k8snode2
192.168.2.213  k8snode3


docker版本

[root@k8smaster ~]# docker --versionDocker version 19.03.13, build 4484c46d9d


k8s版本

kubectl versionClient Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:50:19Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:41:49Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}


安装要点步骤:

hostnamectl set-hostname k8smaster
/etc/hosts192.168.2.201 k8smaster192.168.2.211 k8snode1192.168.2.212 k8snode2192.168.2.213 k8snode3
/etc/sysconfig/network-scriptsTYPE="Ethernet"PROXY_METHOD="none"BROWSER_ONLY="no"BOOTPROTO="none"DEFROUTE="yes"IPV4_FAILURE_FATAL="no"IPV6INIT="yes"IPV6_AUTOCONF="yes"IPV6_DEFROUTE="yes"IPV6_FAILURE_FATAL="no"IPV6_ADDR_GEN_MODE="stable-privacy"NAME="enp0s3"UUID="11ce90bd-0019-404d-a5c3-814fba854948"DEVICE="enp0s3"ONBOOT="yes"IPADDR="192.168.2.201"PREFIX="24"GATEWAY="192.168.2.1"IPV6_PRIVACY="no"DNS1=223.5.5.5

 2、关闭防火墙

systemctl stop firewalldsystemctl disable firewalld

3、关闭swap,设置selinux

swapoff -a && sed -i '/swap / s/^\(.*\)$/#\1/g' /etc/fstabsetenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config


4、配置系统参数

cat > /etc/sysctl.d/k8s.conf <<EOFnet.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1net.ipv4.ip_forward=1net.ipv4.tcp_tw_recycle=0vm.swappiness=0vm.panic_on_oom=0fs.inotify.max_user_instances=8192fs.inotify.max_user_watches=1048576fs.file-max=52706963fs.nr_open=52706963net.ipv6.conf.all.disable_ipv6=1net.netfilter.nf_contrack_max=2310720EOFsysctl -p /etc/sysctl.d/k8s.conf


5、配置阿里源

rm -rfv /etc/yum.repos.d/*curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo

6、安装相关包

yum install vim bash-completion net-tools gcc -ywget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpmyum install containerd.io-1.2.6-3.3.el7.x86_64.rpm

7、安装docker

yum install -y yum-utils device-mapper-persistent-data lvm2yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoyum -y install docker-ce

8、添加仓库加速器

mkdir -p /etc/dockertee /etc/docker/daemon.json <<-'EOF'{"registry-mirrors": ["https://fl791z1h.mirror.aliyuncs.com"]}EOFsystemctl daemon-reloadsystemctl restart docker


9、添加阿里k8s源

cat <<EOF > /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/enabled=1gpgcheck=1repo_gpgcheck=1gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpgEOF

10、安装k8s

yum install kubectl kubelet kubeadmsystemctl enable kubelet


11、初始化k8s

kubeadm init --kubernetes-version=1.19.3 \--apiserver-advertise-address=192.168.2.201 \--image-repository registry.aliyuncs.com/google_containers \--service-cidr=10.10.0.0/16 --pod-network-cidr=10.122.0.0/16



初始化成功会提示如下信息,需要记录下来后增加node节点使用

kubeadm join 192.168.2.201:6443 --token g6uqxu.0irn24hzmvwwni6t \--discovery-token-ca-cert-hash sha256:b695db7c0e6e5b4aaecad70ec6e8ff3463811530ead0f69e84e7b0136636ef33


node节点只是比master节点少一个初始化,其余相同,完成后启动docker、kubelet

然后使用上面命令完成node节点加入


node状态

[root@k8smaster ~]# kubectl get nodeNAME STATUS ROLES AGE VERSIONk8smaster Ready master 4h18m v1.19.3k8snode1 Ready <none> 41m v1.19.3k8snode2 Ready <none> 22m v1.19.3k8snode3 Ready <none> 22m v1.19.3


以上是关于centos8上部署k8s的主要内容,如果未能解决你的问题,请参考以下文章

centos8搭建k8s集群

docker安装教程(windows和linux[centos8])

导致资产预编译在heroku部署上失败的代码片段

在centos8上部署springboot 项目

CentOS8部署自己本地的django项目

centos8部署MySQL5.7故障集