Skip to content

Single-Node Setup

Single-Node Cluster Installation

Setting up a single-node Kubernetes cluster is an essential first step for learning Kubernetes. This section covers three common methods: kubeadm, kops, and Minikube. Each approach has its use cases, from bare-metal setups to local development environments.


Using kubeadm (Manual Setup)

kubeadm is a tool for bootstrapping clusters, ideal for testing or small-scale deployments. It requires a clean Linux environment with prerequisites installed.

Prerequisites

  • Linux distribution (Ubuntu, CentOS, etc.)
  • Disable swap: sudo swapoff -a
  • Ensure kernel is up to date

Step-by-Step

  1. Install Kubernetes components:

    sudo apt update && sudo apt install -y kubelet kubeadm kubectl
    sudo apt-mark hold kubelet kubeadm kubectl
    

  2. Initialize the cluster:

    sudo kubeadm init --pod-network-cidr=10.244.0.0/16
    
    This creates the API server, etcd, and kubelet services. The output includes a kubeadm join command for worker nodes (not needed for single-node).

  3. Configure kubeconfig:

    sudo cp /etc/kubernetes/admin.conf $HOME/
    sudo chown $(id -u):$(id -g) $HOME/admin.conf
    export KUBECONFIG=$HOME/admin.conf
    

  4. Install a CNI plugin (e.g., Calico):

    kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
    

  5. Verify the cluster:

    kubectl get nodes
    


Using kops (Cloud-Native Setup)

kops (Kubernetes Operations) is designed for managing clusters on cloud providers like AWS, GCP, or Azure. It can also be used with local VMs, though it’s more suited for multi-node clusters.

Prerequisites

  • Cloud provider account (or local VM setup)
  • kops CLI installed

Step-by-Step

  1. Create a cluster configuration (example for AWS):

    apiVersion: kops.k8s.io/v1alpha2
    kind: Cluster
    metadata:
      name: my-cluster.example.com
      region: us-east-1
    spec:
      kubernetesVersion: stable
      subnets:
        - us-east-1a
        - us-east-1b
      masterCount: 1
      nodeCount: 1
      nodeVolumeSize: 20
    

  2. Create and configure the cluster:

    kops create cluster --name=my-cluster.example.com --state=s3://my-bucket --node-count=1 --master-count=1
    kops update cluster --name=my-cluster.example.com --state=s3://my-bucket --yes
    

  3. Access the cluster:

    kops get cluster
    kops get nodes
    

Note: For local VMs, replace S3 storage with a local path and adjust networking.


Using Minikube (Local Development)

Minikube is perfect for developers needing a lightweight, isolated Kubernetes environment. It runs a single-node cluster in a VM or Docker container.

Prerequisites

  • Docker or a hypervisor (e.g., VirtualBox)
  • Minikube CLI installed

Step-by-Step

  1. Start Minikube:

    minikube start --driver=virtualbox
    
    Replace virtualbox with docker if using Docker.

  2. Verify the cluster:

    kubectl get nodes
    

  3. Deploy a sample app (e.g., Nginx):

    kubectl create deployment nginx --image=nginx
    kubectl expose deployment nginx --type=LoadBalancer --port=80
    kubectl get services
    

  4. Access the app:

    minikube service nginx
    


Key takeaways

  • kubeadm is ideal for manual, bare-metal setups but requires careful configuration.
  • kops excels in cloud environments but is more complex for single-node use.
  • Minikube is the simplest choice for local development, offering quick setup and teardown.
  • All methods require attention to system requirements (e.g., swap disabled, kernel updates).