Ubuntu 22.10 安装 k8s 1.25.3

k8s相关内容

  1. 安装 openssh-server,提供远程连接

    sudo apt install -y openssh-server
    
    # 修改root用户的密码
    sudo passwd root
    
    # 修改ssh配置文件
    sudo vi /etc/ssh/sshd_config
    
    # 允许root用户远程连接
    PermitRootLogin yes
    
    # 重启 ssh
    sudo systemctl restart ssh
    # /etc/init.d/ssh restart
    
  2. 使用 root 用户执行以下命令

  3. 安装 vim

    sudo apt install -y vim
    
  4. 安装 vim

    sudo apt install -y wget
    
  5. 将主机名指向本机IP,主机名只能包含:字母、数字、-(横杠)、.(点)

    1. 获取主机名
      hostname
      
    2. 临时设置主机名
      hostname 主机名
      
    3. 永久设置主机名
      sudo echo '主机名' > /etc/hostname
      
    4. 编辑 hosts
      sudo vim /etc/hosts
      
  6. 关闭防火墙

  7. 关闭交换空间

    sudo swapoff -a
    sudo sed -i 's/.*swap.*/#&/' /etc/fstab
    
  8. 安装 Docker

    sudo apt-get remove docker docker-engine docker.io containerd runc
    sudo apt-get update
    
    # 更新apt包索引并安装包以允许apt通过 HTTPS 使用存储库:
    sudo apt-get install -y ca-certificates curl gnupg lsb-release
    
    # 添加 Docker 的官方 GPG 密钥
    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    
    # 设置稳定存储库
    # echo \
    #  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
    #  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    # 由于docker暂未提供 22.10 的安装包,这里使用 22.04 的安装包
     echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
      jammy stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
    sudo apt-get update
    
    # 安装 Docker 引擎
    sudo apt-get update
    sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
    
    sudo docker info
    # sudo systemctl status docker
    sudo systemctl list-unit-files | grep docker
    
    # 启动 docker 时,会启动 containerd
    # sudo systemctl status containerd.service
    
    sudo systemctl stop containerd.service
    
    sudo cp /etc/containerd/config.toml /etc/containerd/config.toml.bak
    sudo containerd config default > $HOME/config.toml
    sudo cp $HOME/config.toml /etc/containerd/config.toml
    
    # 修改 /etc/containerd/config.toml 文件后,要将 docker、containerd 停止后,再启动
    sudo sed -i "s#registry.k8s.io/pause#registry.cn-hangzhou.aliyuncs.com/google_containers/pause#g" /etc/containerd/config.toml
    # https://kubernetes.io/zh-cn/docs/setup/production-environment/container-runtimes/#containerd-systemd
    # 确保 /etc/containerd/config.toml 中的 disabled_plugins 内不存在 cri
    sudo sed -i "s#SystemdCgroup = false#SystemdCgroup = true#g" /etc/containerd/config.toml
    
    sudo systemctl enable --now containerd.service
    # sudo systemctl status containerd.service
    
    # sudo systemctl status docker.service
    sudo systemctl restart docker.service
    # sudo systemctl status docker.service
    sudo systemctl enable docker.service
    systemctl list-unit-files | grep docker
    
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
      "registry-mirrors": ["https://hnkfbj7x.mirror.aliyuncs.com"],
        "exec-opts": ["native.cgroupdriver=systemd"]
    }
    EOF
    
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    sudo docker info
    
    systemctl status docker.service
    
    systemctl status containerd.service
    
  9. 安装 k8s 1.25.3 所需依赖
    文档:Kubernetes镜像

    sudo apt-get update && sudo apt-get install -y apt-transport-https
    curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add - 
    
    sudo vim /etc/apt/sources.list.d/kubernetes.list
    
    deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
    
    sudo apt-get update
    # sudo apt-cache madison kubelet
    # sudo apt-cache madison kubeadm 
    # sudo apt-cache madison kubectl
    sudo apt-get install -y kubelet=1.25.3-00 kubeadm=1.25.3-00 kubectl=1.25.3-00
    sudo systemctl daemon-reload
    sudo systemctl restart kubelet
    sudo systemctl enable kubelet
    
    sudo systemctl status kubelet
    
  10. 已上命令需要在控制面板与node节点执行,并确保没有错误与警告

  11. 已上命令需要在控制面板与node节点执行,并确保没有错误与警告

  12. 已上命令需要在控制面板与node节点执行,并确保没有错误与警告

  13. 控制面板:初始化

    sudo kubeadm init --image-repository=registry.aliyuncs.com/google_containers
    
    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
    
    kubectl cluster-info
    
    # 初始化失败后,可进行重置,重置命令:kubeadm reset
    
    # 执行成功后,会出现类似下列内容:
    # kubeadm join 192.168.61.142:6443 --token 66l0ur.370hug1iiyra1or9 \
    # 	--discovery-token-ca-cert-hash sha256:3f3bacdbc4162511909b066ffccf06226d2c53fb6cefbc9b92789260d001359e 
    
  14. 控制面板:

    kubectl get pods --all-namespaces -o wide
    
    kubectl get nodes
    
    kubectl get cs
    
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐晓伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值