本文主要是介绍Ubuntu18搭建Kubernate集群,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.基本环境
版本介绍
ubuntu 18.04
docker 20.10
kube-apiserver 1.21.3
kube-controller-manage 1.21.3
kube-scheduler 1.21.3
kube-proxy 1.21.3
kubernetes 21.10
2.ubuntu环境必备
Docker环境
参考:Ubuntu18配置Docker
关闭防火墙
ufw disable
关闭selinux , ubuntu系统好像不需要
setenforce 0
关闭swap;第一行是临时禁用,第二行是永久禁用
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
桥接的IPV4流量传递到iptables 的链
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
让配置生效
sysctl --system
3.开始安装(所有机器必备)
配置k8s资源
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
apt-get update
安装nfs
apt-get install nfs-common
安装kubeadm(初始化cluster),kubelet(启动pod)和kubectl(k8s命令工具)
apt install -y kubelet=1.21.3-00 kubeadm=1.21.3-00 kubectl=1.21.3-00
设置开机启动并启动kubelet
systemctl enable kubelet && systemctl start kubelet
配置节点的host数据
192.168.52.129 为主节点ip
echo "192.168.52.129 cluster-endpoint" >> /etc/hosts
4.开始安装(主节点机器必备)
创建文件
vim k8s.sh
chmod 777 k8s.sh
写入脚本
#!/bin/bash
images=(kube-apiserver:v1.21.3kube-controller-manager:v1.21.3kube-scheduler:v1.21.3kube-proxy:v1.21.3pause:3.2etcd:3.4.13-0
)
for imageName in ${images[@]} ; dodocker pull registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName}docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName} k8s.gcr.io/${imageName}docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName}
done
docker pull coredns/coredns:1.8.0
docker tag coredns/coredns:1.8.0 registry.aliyuncs.com/google_containers/coredns:v1.8.0
docker rmi coredns/coredns:1.8.0
执行脚本
./k8s.sh
初始化
192.168.52.129为主节点ip
kubeadm init \
--apiserver-advertise-address=192.168.52.129 \
--control-plane-endpoint=cluster-endpoint \
--image-repository=registry.aliyuncs.com/google_containers \
--kubernetes-version v1.21.10 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=192.168.0.0/16
记录安装成功的日志
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/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou 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/You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:kubeadm join cluster-endpoint:6443 --token euztag.6yjbhn94ehg6nhn7 \--discovery-token-ca-cert-hash sha256:a6e917b751e424c7a761c2276ae02db95d87ba5a3cc6b374182519ce89aba28b \--control-plane Then you can join any number of worker nodes by running the following on each as root:kubeadm join cluster-endpoint:6443 --token euztag.6yjbhn94ehg6nhn7 \--discovery-token-ca-cert-hash sha256:a6e917b751e424c7a761c2276ae02db95d87ba5a3cc6b374182519ce89aba28b
执行配置
mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config
配置插件
curl https://docs.projectcalico.org/v3.20/manifests/calico.yaml -O
kubectl apply -f calico.yaml
5.从节点加入
从主节点获取编码
kubeadm join cluster-endpoint:6443 --token euztag.6yjbhn94ehg6nhn7 \--discovery-token-ca-cert-hash sha256:a6e917b751e424c7a761c2276ae02db95d87ba5a3cc6b374182519ce89aba28b
重新获取令牌(上面那个只有24有效时间)
kubeadm token create --print-join-command
6.查看结果
kubectl get pods -Akubectl get nodes
7.重启,测试集群是否自动恢复
查看结果
kubectl get pods -Akubectl get node
参考
在ubuntu18.04上搭建kubernetes(保姆级教程)_kuboard 支持ubuntu18,04-CSDN博客
Kubernetes · 语雀
这篇关于Ubuntu18搭建Kubernate集群的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!