debian

在Debian上部署Kubernetes有哪些技巧

小樊
44
2025-04-14 06:28:15
栏目: 智能运维

在Debian上部署Kubernetes的技巧主要包括以下几个方面:

环境准备

初始化配置

  1. 关闭防火墙
    systemctl stop firewalld && systemctl disable firewalld
    
  2. 关闭SELinux
    • 永久关闭:
      sed -i 's/enforcing/disabled/' /etc/selinux/config
      
    • 临时关闭:
      setenforce 0
      
  3. 关闭Swap
    • 永久关闭:
      sed -ri '/swap/s/^/#/' /etc/fstab
      
    • 临时关闭:
      swapoff -a
      
  4. 时间同步
    apt-get install -y chrony
    systemctl start chronyd && systemctl enable chronyd
    
  5. 设置主机名
    hostnamectl set-hostname k8s-master
    
  6. 修改hosts文件
    cat >> /etc/hosts << EOF
    <Master内网IP> k8s-master<Worker内网IP> k8s-node1
    #后续添加节点时补充EOF
    EOF
    
  7. 启用内核参数
    cat > /etc/sysctl.d/k8s.conf << EOF
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    net.ipv4.ip_forward = 1
    EOF
    sysctl --system
    

安装Docker和Kubernetes组件

  1. 安装Docker
    apt-get update
    apt-get install -y apt-transport-https ca-certificates curl
    curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
    echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
    sudo apt-get update
    sudo apt-get install -y docker-ce docker-ce-cli containerd.io
    sudo systemctl start docker && sudo systemctl enable docker
    
  2. 配置Docker镜像加速
    cat > /etc/docker/daemon.json << EOF
    {
      "registry-mirrors": ["https://registry.docker-cn.com", "https://pee6w651.mirror.aliyuncs.com"],
      "exec-opts": ["native.cgroupdriver=systemd"]
    }
    EOF
    sudo systemctl restart docker
    
  3. 添加Kubernetes源
    cat > /etc/apt/sources.list.d/kubernetes.list << EOF
    deb https://packages.cloud.google.com/apt/repository/kubernetes-xenial main
    EOF
    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
    sudo apt-get update
    
  4. 安装kubeadm、kubelet、kubectl
    sudo apt-get install -y kubelet kubeadm kubectl
    sudo apt-mark hold kubelet kubeadm kubectl
    

部署Master节点

sudo kubeadm init --apiserver-advertise-address=<Master外网IP> --image-repository registry.aliyuncs.com/google_conta

以上步骤为在Debian上部署Kubernetes的基本流程和一些关键技巧。请注意,这些步骤可能会随着Kubernetes版本的更新而发生变化,建议在部署前查阅最新的官方文档。

0
看了该问题的人还看了