centos8上部署k8s
Posted 数据库平台优化
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos8上部署k8s相关的知识,希望对你有一定的参考价值。
操作系统版本
cat /etc/redhat-release
CentOS 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 --version
Docker version 19.03.13, build 4484c46d9d
k8s版本
kubectl version
Client 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/hosts
192.168.2.201 k8smaster
192.168.2.211 k8snode1
192.168.2.212 k8snode2
192.168.2.213 k8snode3
/etc/sysconfig/network-scripts
TYPE="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 firewalld
systemctl disable firewalld
3、关闭swap,设置selinux
swapoff -a && sed -i '/swap / s/^\(.*\)$/#\1/g' /etc/fstab
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
4、配置系统参数
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0
vm.panic_on_oom=0
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_contrack_max=2310720
EOF
sysctl -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 -y
wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
yum install containerd.io-1.2.6-3.3.el7.x86_64.rpm
7、安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
8、添加仓库加速器
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://fl791z1h.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
9、添加阿里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
10、安装k8s
yum install kubectl kubelet kubeadm
systemctl 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 node
NAME STATUS ROLES AGE VERSION
k8smaster Ready master 4h18m v1.19.3
k8snode1 Ready <none> 41m v1.19.3
k8snode2 Ready <none> 22m v1.19.3
k8snode3 Ready <none> 22m v1.19.3
以上是关于centos8上部署k8s的主要内容,如果未能解决你的问题,请参考以下文章