注解:看懂需要一定的基础
角色 | IP |
---|---|
master1 | 192.168.0.221 |
node1 | 192.168.0.222 |
node2 | 192.168.0.223 |
node3 | 192.168.0.224 |
k8s-node-01 | 192.168.0.245 |
apt-get install ntpdate -y
ntpdate time.windows.com
cat <
EOF
cat <
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
swapoff -a # 临时
sed -ri ‘s/.swap./#&/’ /etc/fstab # 永久
1 安装
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install
apt-transport-https
ca-certificates
curl
gnupg
lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
$ echo
“deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu
$(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update
$ sudo apt-get install containerd.io
mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
sed -i ‘s/SystemdCgroup = false/SystemdCgroup = true/’ /etc/containerd/config.toml &&
grep ‘SystemdCgroup’ -B 11 /etc/containerd/config.toml
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
BinaryName = ""
CriuImagePath = ""
CriuPath = ""
CriuWorkPath = ""
IoGid = 0
IoUid = 0
NoNewKeyring = false
NoPivotRoot = false
Root = ""
ShimCgroup = ""
SystemdCgroup = true
sed -i ‘s#endpoint = “”#endpoint = “https://xx4bwyg2.mirror.aliyuncs.com”#g’ /etc/containerd/config.toml &&
grep ‘endpoint’ -B 5 /etc/containerd/config.toml
sed -i ‘s#sandbox_image = "k8s.gcr.io/pause#sandbox_image = “registry.aliyuncs.com/google_containers/pause”#g’ /etc/containerd/config.toml &&
grep ‘sandbox_image’ /etc/containerd/config.toml
systemctl daemon-reload
systemctl restart containerd.service
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo “deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main” | sudo tee /etc/apt/sources.list.d/kubernetes.list
apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
kubeadm config print init-defaults > kubeadm-config.yaml
vi kubeadm-config.yaml
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
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.24.0
networking:
dnsDomain: cluster.local
serviceSubnet: 10.96.0.0/12
scheduler: {}
kubeadm init --config kubeadm-init.yaml
#如何根据配置文件,列出和拉取镜像
kubeadm config images list --config kubeadm-config.yaml
kubeadm config images pull --config kubeadm-config.yaml