注解:看懂需要一定的基础

ip规划

角色IP
master1192.168.0.221
node1192.168.0.222
node2192.168.0.223
node3192.168.0.224
k8s-node-01192.168.0.245

时间同步

apt-get install ntpdate -y
ntpdate time.windows.com

允许 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
sudo sysctl --system

Ubuntu 18.04 下关闭 swap 的操作

关闭swap

swapoff -a # 临时
sed -ri ‘s/.swap./#&/’ /etc/fstab # 永久

安装containerd.io

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

生成containerd默认配置文件

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

老版本要手动追加这个参数SystemdCgroup = true
显示内容
      [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

安装 K8S

安装 K8S软件包

更新 apt 包索引并安装使用 Kubernetes apt 仓库所需要的包:

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl

下载 Google Cloud 公开签名秘钥:

sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

添加 Kubernetes apt 仓库:

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 </etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF

更新 apt 包索引,安装 kubelet、kubeadm 和 kubectl,并锁定其版本:

apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

部署Kubernetes Master

6.1 创建kubeadm配置文件

导出默认初始化配置

kubeadm config print init-defaults > kubeadm-config.yaml

vi kubeadm-config.yaml

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.0.221
      bindPort: 6443
      nodeRegistration:
      criSocket: /run/containerd/containerd.sock
      imagePullPolicy: IfNotPresent
      name: master
      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.24.0
networking:
dnsDomain: cluster.local
serviceSubnet: 10.96.0.0/12
scheduler: {}

在master1节点执行
 kubeadm init --config kubeadm-init.yaml

#如何根据配置文件,列出和拉取镜像

kubeadm config images list --config kubeadm-config.yaml
kubeadm config images pull --config kubeadm-config.yaml


Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐