2023-03-03 09:49:24
03 03 2023
摘要:Ubuntu系统安装k8s

1.关闭 swap

临时关闭swap:
swapoff -a
注释/etc/fstab 里面的swap
 
2.使 apt 支持 ssl
apt-get update && apt-get install -y apt-transport-https
 
3.下载 gpg 密钥
 
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
 
4.docker 使用阿里云镜像
 
cat > /etc/docker/daemon.json <<eof
{
"registry-mirrors":["https://qbd2mtyh.mirror.aliyuncs.com"]
}
eof

systemctl daemon-reload #重新加载镜像

5.添加 k8s 镜像源

cat > /etc/apt/sources.list.d/kubernetes.list <<EOF
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
6.更新源列表
apt update -y
 
7.安装 kubectl,kubeadm 以及 kubelet
apt install kubeadm=1.23.6-00 kubelet=1.23.6-00 kubectl=1.23.6-00
 
8.运行 kubeadm init设置主节点
kubeadm init --apiserver-advertise-address=192.168.2.120 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version=1.23.6 --service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \ #这里建议不修改,修改后得修改kube-flannel.yml
--ignore-preflight-errors=all
9.安装成功保存输出的内容

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

Alternatively, if you are the root user, you can run:

  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.2.120:6443 --token 5npykw.tyxxjgmu7k01a0h9 \
        --discovery-token-ca-cert-hash sha256:5f0edccfab5dc301e214015fb527f4fd525dbb96da8dbc4a2d33513e849xxxxx
 
10.执行
  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
  export KUBECONFIG=/etc/kubernetes/admin.conf
11.安装flannel
 
 kubectl apply -f kube-flannel.yml
 
12.将 master 标记为可调度
 
  kubectl taint nodes 主节点 node-role.kubernetes.io/master-
  
 
  kubectl describe node 主节点|grep Taints #查看主节点是否可调度
 
13.安装子节点重复上面1-7步骤
14.子节点加入集群
 
kubeadm join 192.168.2.120:6443 --token 5npykw.tyxxjgmu7k01a0h9 \
        --discovery-token-ca-cert-hash sha256:5f0edccfab5dc301e214015fb527f4fd525dbb96da8dbc4a2d33513e849xxxxx
15.重新初始化子节点
 kubeadm reset
 在执行第8步
 
k8s的官网:https://kubernetes.io/

延伸阅读
  1. 上一篇:JDK
  2. 下一篇:Nginx
发表评论