kubeadm安装k8s1.20.0
kubeadm安装k8s1.20.01、欢系统环境设置2、kube-proxy开启ipvs的前置条件3、安装docker4、安装kubeadm初始化master节点1、欢系统环境设置注意:机器要求安装 k8s 的节点必须是大于 1 核心的 CPU机器功能192.168.66.10k8s-master01192.168.66.20k8s-node01192.168.66.21k8s-node0219
·
kubeadm安装k8s1.20.0
1、欢系统环境设置
注意:机器要求安装 k8s 的节点必须是大于 1 核心的 CPU
机器 | 功能 |
---|---|
192.168.66.10 | k8s-master01 |
192.168.66.20 | k8s-node01 |
192.168.66.21 | k8s-node02 |
192.168.66.100 | manager |
设置机器名
#hostnamectl set-hostname k8s-master01
#hostnamectl set-hostname k8s-node01
#hostnamectl set-hostname k8s-node02
所有机器上安装依赖包
#yum install conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget net-tools git -y
关闭防火墙
#systemctl stop firewalld && systemctl disable firewalld
安装iptables
#yum -y install iptables-services
#systemctl start iptables && systemctl enable iptables
#iptables -F && service iptables save
关闭 SeLinux
#swapoff -a
#sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
#setenforce 0
#sed -i -r 's#(^SELIN.*=)enforcing#\1disable#g' /etc/selinux/config
调整内核参数
#cat > kubernetes.conf << EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0
vm.overcommit_memory=1
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_conntrack_max=2310720
EOF
#cp kubernetes.conf /etc/sysctl.d/
#sysctl -p /etc/sysctl.d/kubernetes.conf
调整时区
#timedatectl set-timezone Asia/Shanghai
#timedatectl set-local-rtc 0
#systemctl restart rsyslog
#systemctl restart crond
关闭系统不需要的服务
#systemctl stop postfix && systemctl disable postfix
设置rsyslogd和systemd journald
#mkdir /var/log/journal
#mkdir /etc/systemd/journald.conf.d
#cat > /etc/systemd/journald.conf.d/99-prophet.conf <<EOF
[Journal]
Storage=persistent
Compress=yes
SyncIntervalSec=5m
RateLimitInteerval=30s
RateLimitBurst=1000
SystemMaxUse=10G
SystemMaxFileSize200M
MaxRetentionSec=2week
ForwardToSyslog=no
EOF
#systemctl restart systemd-journald
升级centos内核
#rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
#yum --enablerepo=elrepo-kernel install -y kernel-lt
#grub2-set-default 'CentOS Linux (4.4.189-1.el7.elrepo.x86_64) 7 (Core)'
2、kube-proxy开启ipvs的前置条件
#modprobe br_netfilter
#cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack
EOF
#chmod 775 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules &&
lsmod | grep -e ip_vs -e nf_conntrack
3、安装docker
安装最新的docker容器
#yum install -y yum-utils device-mapper-persistent-data lvm2
#yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#yum update -y && yum install -y docker-ce
创建/etc/docker目录
#mkdir /etc/docker
#cat > /etc/docker/daemon.json <<EOF
{
"exec-opts":["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {"max-size":"100m"}
}
EOF
#mkdir -p /etc/systemd/system/docker.service.d
重启docker服务
#systemctl daemon-reload && systemctl restart docker && systemctl enable docker
4、安装kubeadm
#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
安装kubeadm服务(这里根据自己的需要,可以自行调整版本)
#yum -y install kubeadm-1.20.0 kubectl-1.20.0 kubelet-1.20.0
#systemctl enable kubelet.service
初始化master节点
导出默认的配置文件
[root@k8s-master01 ~]# kubeadm config print init-defaults > kubeadm-config.yaml
#vi kubeadm-config.yaml
修改文件中的
advertiseAddress: 192.168.66.10
#这个是阿里云的镜像仓库,下载速度还可以
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
networking:
dnsDomain: cluster.local
podSubnet: "10.244.0.0/16"
serviceSubnet: 10.96.0.0/12
scheduler: {}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs
初始化master
#kubeadm init --config kubeadm-config.yaml --upload-certs|tee kubeadm-init.log
最后看到下面的内容就代表成功了
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.66.10:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:fc34bfa6b7433177f004125cab77619cc9b1fd9d116166ad545d2479dc4ebeb2
我们在另外的两个node上执行join就可以建立好环境了
#kubeadm join 192.168.66.10:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:fc34bfa6b7433177f004125cab77619cc9b1fd9d116166ad545d2479dc4ebeb2
5、设置flannel网络
所有节点上添加
[root@k8s-node01 ~]# vi /run/flannel/subnet.env
FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.1.1/24
FLANNEL_MTU=1500
FLANNEL_IPMASQ=false
更多推荐
已为社区贡献2条内容
所有评论(0)