Kubernetes安装(ubuntu20+k8s v1.23.6)
Kubernetes、Ubuntu
两台服务器提前设置hostname及配置hosts
192.168.18.134 k8s-master01
192.168.18.137 k8s-node01
系统环境 Ubuntu20
设置时间同步服务
未设置
设置防火墙关闭
sudo ufw disable && sudo ufw status
关闭Swap
sudo swapoff -a
更新索引
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
安装docker
添加Docker官方的GPG证书,以验证程序包签名
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
为apt添加稳定版本的Docker-CE仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
更新apt索引后安装docker-ce
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
配置Docker。编辑/etc/docker/daemon.json
新建/etc/docker/daemon.json文件
{
"exec-opts":["native.cgroupdriver=systemd"],
"log-driver":"json-file",
"log-opts":{
"max-size":"100m"
},
"storage-driver":"overlay2"
}
启动Docker服务,并设置服务可随系统引导启动
sudo systemctl daemon-reload
sudo systemctl start docker.service
sudo systemctl enable docker.service
安装Kubernetes
切换root
更新apt索引信息后安装必要的程序包,切换root
apt update && apt install -y apt-transport-https
添加Kubernetes官方程序密钥
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
在配置文件/etc/apt/sources.list.d/kubernetes.list中添加如下内容,为apt添加Kubernetes程序包仓库
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
更新程序包索引并安装程序包
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
初始化控制平面
sudo kubeadm init --apiserver-advertise-address=192.168.18.134 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.23.6 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
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
Alternatively, if you are the root user, you can run:
sudo export KUBECONFIG=/etc/kubernetes/admin.conf
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.18.134:6443 --token 72gnv3.b9ybgdnf24z8mce9 --discovery-token-ca-cert-hash sha256:67d547fd7d5262e26b73e09409af14be1994abc4e9cb2407366e31c8f09fe880
部署Flannel网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
验证:
root@k8s-master01:~# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master01 NotReady control-plane,master 23h v1.23.6
节点上重复执行上述除init以上的步骤,然后执行join:
kubeadm join 192.168.18.134:6443 --token 72gnv3.b9ybgdnf24z8mce9 --discovery-token-ca-cert-hash sha256:67d547fd7d5262e26b73e09409af14be1994abc4e9cb2407366e31c8f09fe880
验证:
root@k8s-master01:/etc# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master01 NotReady control-plane,master 23h v1.23.6
k8s-node01 Ready <none> 23h v1.23.6
更多推荐
所有评论(0)