1.禁止swap分区(必须)
暂时禁止:
sudo swapoff -a
永久禁止:
# 注释掉swap一行
sudo vi /etc/fstab
2.更改net.bridge.bridge-nf-call-iptables的值为1.(Ubuntu 20.04默认为1)
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
3.安装Docker
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
开始安装K8S
1.安装kubeadm kubeadm kubectl
sudo apt-get update && sudo apt-get install -y ca-certificates curl software-properties-common apt-transport-https curl
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
sudo tee /etc/apt/sources.list.d/kubernetes.list <<EOF
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
2.初始化
初始化我们使用配置文件的方式进行部署
创建默认的kubeadm-config.yaml文件
sudo kubeadm config print init-defaults > kubeadm-config.yaml
我的配置文件:
注意:就修改标注的这2处就可以了,其他还使用默认生成的配置,因为版本不一样。
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: abcdef.0123456789abcdef
ttl: 24h0m0s
usages:
- signing
- authentication
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 192.168.1.73 # 修改成本地内网ip
bindPort: 6443
nodeRegistration:
criSocket: /var/run/dockershim.sock
imagePullPolicy: IfNotPresent
name: node
taints: null
---
apiServer:
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers # 使用阿里源
kind: ClusterConfiguration
kubernetesVersion: 1.22.0
networking:
dnsDomain: cluster.local
serviceSubnet: 10.96.0.0/12
scheduler: {}
安装master节点
# 日志级别为 5 可能会产生大量的输出 可以方便我们查看报错信息
sudo kubeadm init --config kubeadm-config.yaml --v=5
如果kubeadm init
初始化失败可以使用重置命令。
# 重置
sudo kubeadm reset
3.看是否安装成功
日志出现一下代码表示安装成功、然后根据步骤进行操作就OK了:
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
4.排查问题
排查这类问题的方法是执行如下命令查看具体错误原因:
journalctl -fxeu kubelet
相关命令:
kubectl get pods -n kube-system # 验证k8s是否安装成功
systemctl start kubelet
sudo systemctl start docker
官方文档:https://kubernetes.io/zh-cn/docs/home/
https://www.cnblogs.com/wwph/p/14203626.html