kubeadm init

The kubeadm init command is used to bootstrap the first control plane node in a Kubernetes cluster. Here's how you can initialize a control plane node step-by-step:


1. Prerequisites

Ensure the Following:

  • Operating System: Use a supported Linux distribution (e.g., Ubuntu, CentOS, etc.).
  • Container Runtime: Install a supported container runtime like containerd or CRI-O.
  • kubeadm, kubelet, kubectl Installed: Install these tools using your package manager.
    apt update && apt install -y kubeadm kubelet kubectl
    
    Or on CentOS:
    yum install -y kubeadm kubelet kubectl
    
  • Swap Disabled:
    swapoff -a
    sed -i '/swap/d' /etc/fstab
    
  • Firewall Ports Open: Allow necessary Kubernetes ports such as 6443, 2379-2380, 10250, 10259, 10257. For example:
    sudo ufw allow 6443/tcp
    sudo ufw allow 2379:2380/tcp
    sudo ufw allow 10250:10259/tcp
    

2. Run kubeadm init to Bootstrap the First Control Plane

Basic Command

Run the following command on the first control plane node:

sudo kubeadm init --pod-network-cidr=<CIDR> --control-plane-endpoint=<endpoint>
  • Options:
    • --pod-network-cidr=<CIDR>: The CIDR range for the pod network (e.g., 192.168.0.0/16 for Calico).
    • --control-plane-endpoint=<endpoint>: A stable hostname or IP address for your control plane (e.g., a load balancer). If not available, use the current node's IP.

Example:

sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --control-plane-endpoint=192.168.1.10:6443

Advanced Configuration with kubeadm-config.yaml

If you need more control, use a configuration file:

  1. Create a file kubeadm-config.yaml:
    apiVersion: kubeadm.k8s.io/v1beta3
    kind: ClusterConfiguration
    kubernetesVersion: "v1.28.0"
    controlPlaneEndpoint: "192.168.1.10:6443"  # Use load balancer IP if available
    networking:
      podSubnet: "192.168.0.0/16"  # For Calico or other CNI
    
  2. Initialize the cluster using:
    sudo kubeadm init --config kubeadm-config.yaml
    

3. Post-Initialization Steps

After kubeadm init completes, it outputs instructions for further setup:

Set up kubeconfig:

To use kubectl as a non-root user:

mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Deploy a Pod Network Add-on:

Install a CNI (Container Network Interface) plugin for pod networking. For example:

  • Calico:
    kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
    
  • Weave Net:
    kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')
    

4. Join Additional Control Plane Nodes

To add more control plane nodes, retrieve the kubeadm join command:

kubeadm token create --print-join-command

This will look like:

kubeadm join <control-plane-endpoint>:6443 --token <token> \
    --discovery-token-ca-cert-hash sha256:<hash> \
    --control-plane

Run this on the additional control plane nodes.


5. Verify the Control Plane

Check the status of the control plane:

kubectl get nodes

Ensure the node is in a Ready state.


Let me know if you encounter specific issues during this process, and I can assist further!

댓글

이 블로그의 인기 게시물

To switch to a specific tag in a Git repository

How to checkout branch of remote git, 깃 리모트 브랜치 체크아웃

Using the MinIO API via curl

To download a file from MinIO using Spring Boot, 스프링부트 Minio 사용하기

리눅스의 부팅과정 (프로세스, 서비스 관리)

Chromium 개발 환경 세팅, 크로미움 개발 준비하기

Joining an additional control plane node to an existing Kubernetes cluster

urllib3 with proxy settings

CDPEvents in puppeteer

Avro + Grpc in python