ubuntu-22.04.4(lts)环境在线安装kubernetes1.30

1、基础环境准备
  • 禁止ipv6

修改配置文件

sudo vi /etc/default/grub

修改项

GRUB_CMDLINE_LINUX="ipv6.disable=1"

使修改生效(如果没有生效的话就重启系统),可通过ip a检查

update-grub
  • 禁止swap

修改配置文件

sudo vi /etc/fstab

注释完后重启,可通过free -m检查

#/swap.img      none    swap    sw      0       0
  • 取消禁止ipv4转发

修改配置文件

sudo vi /etc/sysctl.conf

取消注释以下配置项

net.ipv4.ip_forward=1
  • 避免集群不稳定,设置静态IP

修改配置文件

/etc/netplan/00-installer-config.yaml

调整为以下内容,其中静态ip设置为192.168.1.100

network:
  ethernets:
    ens32:
      dhcp4: false
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [192.168.1.1]
  version: 2
  • 安装containerd
sudo apt install containerd
  • containerd配置支持cgroup

修改配置文件/etc/containerd/config.toml,修改SystemdCgrouptrue,若不存在此配置文件,可先创建目录然后导出配置

mkdir /etc/containerd
containerd config default > /etc/containerd/config.toml
SystemdCgroup = true
2、安装kubernetes集群
  • 更新系统并配置源
sudo apt-get update -y
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update -y
  • 安装kubernetes工具
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
  • 可以查看安装集群所需依赖的镜像,可提前pull
kubeadm config images list
kubeadm config images pull

当然也可以单独通过ctr命令来单独拉取镜像

ctr -n k8s.io images pull registry.k8s.io/kube-apiserver:v1.30.7
ctr -n k8s.io images pull registry.k8s.io/kube-controller-manager:v1.30.7
ctr -n k8s.io images pull registry.k8s.io/kube-scheduler:v1.30.7
ctr -n k8s.io images pull registry.k8s.io/kube-proxy:v1.30.7
ctr -n k8s.io images pull registry.k8s.io/coredns/coredns:v1.11.3
ctr -n k8s.io images pull registry.k8s.io/pause:3.9
ctr -n k8s.io images pull registry.k8s.io/etcd:3.5.15-0

基础镜像是在k8s.io命名空间中,可以看到一些已经下载的镜像

ctr -n k8s.io images  list
  • 初始化集群
sudo kubeadm init --apiserver-advertise-address 192.168.1.100

正常初始化完集群后按提示执行命令即可

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.1.100:6443 --token ox6fbq.wahu0ywb0cgdk00y \
        --discovery-token-ca-cert-hash sha256:ffea1a82169b43bf3fc96a0e37ccb7fc96df32c4bb735924016c017c8e967d8a 
  • 安装网络组件calico
curl https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/calico.yaml -O
kubectl apply -f calico.yaml
  • 检查集群情况
kubectl version
kubectl get componentstatus
kubectl get node
kubectl get po -A

kubernetes v1.30.7


赞赏(Donation)
微信(Wechat Pay)

donation-wechatpay