kubeadm部署k8s v1.30

k8s 1.30主要新功能

  • kubelet 重启后稳健的 VolumeManager 重建(SIG Storage)

  • 防止在卷还原过程中未经授权的卷模式转换(SIG Storage)

  • Pod 调度可用性(SIG Scheduling)

  • PodTopologySpread 中的最小域数(SIG Scheduling)

  • k/k 中的 Go 工作区(SIG Architecture))

  • 节点日志查询(Windows SIG Scheduling)

  • CRD 验证棘轮(SIG API Machinery)

  • 上下文日志记录(SIG Instrumentation)

  • 使 Kubernetes 了解负载均衡行为(SIG Network)

Kubernetes v1.30 的升级、弃用和移除

升级至稳定版 以下是升级至稳定版(也称为正式发布版)的所有功能列表。有关包括新功能和从 alpha 到 beta 的升级的完整更新列表,请查阅发布说明。

此版本包含了共 17 个功能的升级至稳定版:

弃用和移除:

  • 自 v1.27 版本起,已移除对 SecurityContextDeny 准入插件的支持,并标记为弃用。(SIG Auth、SIG Security 和 SIG Testing)
  • 随着 SecurityContextDeny 准入插件的移除,建议使用自 v1.25 版本起可用的 Pod Security Admission 插件。

一、环境准备

1.1、服务器信息

IP地址 角色 CPU/内存 主机名 操作系统
192.168.110.8 master 4c/4G master CentOS 7.6
192.168.110.9 node1 4c/4G node1 CentOS 7.6

1.2、ip和主机名解析

shell 复制代码
$ cat /etc/hosts

192.168.110.8 master
192.168.110.9 node1

1.3、关闭防火墙和selinux

she 复制代码
$ systemctl stop firewalld && systemctl disable firewalld

$ setenforce 0

$ sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

1.4、禁用swap分区

shell 复制代码
$ swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab 

1.5、修改内核参数并加载

#开启ipv4转发

shell 复制代码
$ cat >> /etc/sysctl.d/k8s.conf << EOF
vm.swappiness=0
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

$ modprobe br_netfilter &&  modprobe overlay && sysctl -p /etc/sysctl.d/k8s.conf	

注:其中1.2 - 1.5在所有节点进行操作

二、安装docker

k8s在 v1.24及以上版本由于弃用dockershim后,无法直接使用docker,需要安装cri-docker,推荐直接使用containerd,这里由于个人习惯问题,部署docker+cri-docker配合使用

2.1、安装docker

shell 复制代码
$ yum install -y yum-utils device-mapper-persistent-data lvm2
 
$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 
$ yum install -y docker-ce

$ systemctl start docker && systemctl enable docker

2.2、配置daemon.json

#主要设置驱动为systemd,systemd在资源紧张的情况下比cgroups更加稳定

shell 复制代码
$ cat /etc/docker/daemon.json
{
  "exec-opts": [
      "native.cgroupdriver=systemd"
  ],
  "registry-mirrors": [
            "http://hub-mirror.c.163.com/",
            "https://docker.mirrors.ustc.edu.cn/",
            "https://fz5yth0r.mirror.aliyuncs.com",
            "https://registry.docker-cn.com"
        ],
  "data-root":"/var/lib/docker",
  "storage-driver": "overlay2",
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m",
    "max-file": "3"
  }
}

2.3、安装cri-docker

shell 复制代码
$ curl -LO https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.13/cri-dockerd-0.3.13-3.el7.x86_64.rpm

$ rpm -ivh cri-dockerd-0.3.13-3.el7.x86_64.rpm

#验证版本
$ cri-dockerd --version

#启动服务
$ systemctl start cri-docker && systemctl enable cri-docker

三、部署、配置k8s

3.1、配置yum源

shell 复制代码
$ cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF

#更新yum缓存
$ yum clean all  && yum makecache

3.2、安装kubectl等组件

shell 复制代码
$ yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
$ systemctl enable --now kubelet

3.3、整合kubelet和cri-docker

shell 复制代码
#修改/usr/lib/systemd/system/cri-docker.service文件的ExecStart字段
ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --network-plugin=cni --cni-bin-dir=/opt/cni/bin --cni-cache-dir=/var/lib/cni/cache --cni-conf-dir=/etc/cni/net.d


#重启cri-dockerd服务
$ systemctl daemon-reload && systemctl restart cri-docker


#配置kubelet服务, 修改/etc/sysconfig/kubelet文件的KUBELET_KUBEADM_ARGS字段
KUBELET_KUBEADM_ARGS="--container-runtime-endpoint=/run/cri-dockerd.sock"

3.4、预拉取镜像

shell 复制代码
$ kubeadm config images pull  --cri-socket unix:///var/run/cri-dockerd.sock --image-repository registry.aliyuncs.com/google_containers

3.5、kubeadm初始化集群

shell 复制代码
$ kubeadm init \
--apiserver-advertise-address=192.168.110.8 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.30.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--token-ttl=0 \
--upload-certs \
--cri-socket unix:///var/run/cri-dockerd.sock


#输出如下
====================================================================
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.110.8:6443 --token t9zogk.j7sak404br83rdqq \
        --discovery-token-ca-cert-hash sha256:db17d1cb5bbb30e7ad2e7876b89365053d017c765f9b081e5a1e16249db13eb7

提示registry.k8s.io/pause:3.9镜像未找到

解决方案:

shell 复制代码
$ docker pull registry.aliyuncs.com/google_containers/pause:3.9

$ docker tag registry.aliyuncs.com/google_containers/pause:3.9 registry.k8s.io/pause:3.9

3.4、安装网络插件

shell 复制代码
$ kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

3.5、负载节点加入集群

shell 复制代码
$ kubeadm join 192.168.110.8:6443 --token t9zogk.j7sak404br83rdqq         --discovery-token-ca-cert-hash sha256:db17d1cb5bbb30e7ad2e7876b89365053d017c765f9b081e5a1e16249db13eb7 --cri-socket unix:///var/run/cri-dockerd.sock


#验证集群:
[root@master ~]# kubectl  get no
NAME     STATUS   ROLES           AGE    VERSION
master   Ready    control-plane   17m    v1.30.0
node1    Ready    <none>          2m2s   v1.30.0

四、部署dashboard

由于新版本dashboard都使用helm进行安装,先需要安装helm

4.1、helm安装

shell 复制代码
$ wget -c https://get.helm.sh/helm-v3.14.4-linux-amd64.tar.gz
$ tar zxvf helm-v3.14.4-linux-amd64.tar.gz
$ cp linux-amd64/helm /usr/local/bin/

4.2、部署dashboard

shell 复制代码
$ helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
$ helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard

4.3、修改svc为nodeport

shell 复制代码
$ kubectl edit svc -n kubernetes-dashboard kubernetes-dashboard-kong-proxy

#字段  type: NodePort

4.4、获取token

shell 复制代码
$ kubectl -n kubernetes-dashboard create token dashboard-admin
相关推荐
2401_858120538 小时前
Eureka服务下线机制解析:确保服务注册与发现的准确性
云原生·eureka
hay_lee8 小时前
一台docker机器如何实现构建多平台镜像
运维·docker·云原生·容器
The Straggling Crow9 小时前
k8s record 20240705
云原生·容器·kubernetes
lendq9 小时前
k8s-第九节-命名空间
linux·容器·kubernetes
文静小土豆9 小时前
K8S 部署 EFK
云原生·容器·kubernetes
喜欢猪猪9 小时前
Zookeeper底层原理
分布式·zookeeper·云原生
蜗牛乌龟一起走11 小时前
【搭建Nacos服务】centos7 docker从0搭建Nacos服务
运维·docker·容器
acro_0911 小时前
基于python 的动态虚拟主机
运维·服务器·云原生·apache
爽姐想退休14 小时前
Docker国内可用镜像源
docker·容器·json
爱吃龙利鱼14 小时前
k8s学习--基于k8s的ELK日志收集的详细过程
运维·学习·elk·云原生·容器·kubernetes