Bird
Raised Fist0
Kubernetesdevops~10 mins

High availability cluster setup in Kubernetes - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the number of master nodes in a Kubernetes HA cluster.

Kubernetes
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
controlPlaneEndpoint: "loadbalancer.example.com:6443"
controllerManager:
  extraArgs:
    node-monitor-grace-period: "40s"
    node-monitor-period: "5s"
    pod-eviction-timeout: "1m0s"
scheduler:
  extraArgs:
    leader-elect: "true"
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
nodeRegistration:
  name: master-1
  kubeletExtraArgs:
    node-labels: "node-role.kubernetes.io/master="
    authorization-mode: AlwaysAllow
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: JoinConfiguration
controlPlane:
  localAPIEndpoint:
    advertiseAddress: "192.168.1.10"
    bindPort: 6443
  [1]: 3
Drag options to blanks, or click blank then click option'
AmasterCount
BreplicaCount
CcontrolPlaneReplicas
Dreplicas
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'replicaCount' which is common in Helm charts but not in kubeadm config.
Using 'masterCount' which is not a valid kubeadm key.
2fill in blank
medium

Complete the command to initialize the Kubernetes control plane with high availability.

Kubernetes
kubeadm init --control-plane-endpoint [1] --upload-certs
Drag options to blanks, or click blank then click option'
A192.168.1.10:6443
Bloadbalancer.example.com:6443
Cmaster-1:6443
Dlocalhost:6443
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single master node IP instead of the load balancer.
Using localhost which is not accessible externally.
3fill in blank
hard

Fix the error in the kubeadm join command to add a new control plane node.

Kubernetes
kubeadm join loadbalancer.example.com:6443 --token [1] --discovery-token-ca-cert-hash sha256:abcdef1234567890 --control-plane --certificate-key abcdef1234567890
Drag options to blanks, or click blank then click option'
A0123456789abcdef
Babcdef
Cabcdef.0123456789abcdef
Dtoken1234
Attempts:
3 left
💡 Hint
Common Mistakes
Using incomplete or partial token strings.
Omitting the dot separator in the token.
4fill in blank
hard

Fill both blanks to create a Kubernetes Service manifest for the HA control plane load balancer.

Kubernetes
apiVersion: v1
kind: Service
metadata:
  name: kubernetes
  namespace: default
spec:
  type: [1]
  ports:
  - port: 6443
    targetPort: 6443
  selector:
    [2]: master-node
Drag options to blanks, or click blank then click option'
ALoadBalancer
BClusterIP
Capp
Drole
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ClusterIP' which does not expose the service externally.
Using incorrect selector keys like 'app' when 'role' is expected.
5fill in blank
hard

Fill all three blanks to define a Pod Anti-Affinity rule to spread master nodes across failure domains.

Kubernetes
affinity:
  podAntiAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
    - labelSelector:
        matchExpressions:
        - key: [1]
          operator: In
          values:
          - master
      topologyKey: [2]
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions:
        - key: [3]
          operator: In
          values:
          - zone-a
          - zone-b
Drag options to blanks, or click blank then click option'
Akubernetes.io/role
Bkubernetes.io/hostname
Cfailure-domain.beta.kubernetes.io/zone
Dnode-role.kubernetes.io/master
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect label keys for roles or topology.
Confusing node labels with pod labels.

Practice

(1/5)
1. What is the main purpose of setting up a high availability (HA) cluster in Kubernetes?
easy
A. To prevent downtime by having multiple master nodes
B. To reduce the number of worker nodes
C. To speed up pod creation on a single node
D. To disable load balancing between nodes

Solution

  1. Step 1: Understand HA cluster purpose

    High availability clusters are designed to avoid downtime by having multiple master nodes so if one fails, others take over.
  2. Step 2: Compare options

    Options B, C, and D do not relate to preventing downtime or multiple masters.
  3. Final Answer:

    To prevent downtime by having multiple master nodes -> Option A
  4. Quick Check:

    HA cluster = multiple masters for uptime [OK]
Hint: HA means multiple masters to avoid downtime [OK]
Common Mistakes:
  • Thinking HA reduces worker nodes
  • Confusing HA with pod scaling
  • Ignoring the role of multiple masters
2. Which of the following is the correct syntax to initialize a Kubernetes HA cluster using kubeadm with a config file named ha-config.yaml?
easy
A. kubeadm create cluster ha-config.yaml
B. kubeadm start --config=ha-config.yaml
C. kubeadm init --config ha-config.yaml
D. kubeadm init ha-config.yaml

Solution

  1. Step 1: Recall kubeadm init syntax

    The correct command to initialize a cluster with a config file is kubeadm init --config filename.
  2. Step 2: Check options

    kubeadm init --config ha-config.yaml matches the correct syntax. Options A, B, and D use incorrect commands or missing flags.
  3. Final Answer:

    kubeadm init --config ha-config.yaml -> Option C
  4. Quick Check:

    kubeadm init + --config = correct syntax [OK]
Hint: Use 'kubeadm init --config filename' to start HA cluster [OK]
Common Mistakes:
  • Using 'start' instead of 'init'
  • Omitting '--config' flag
  • Passing config file without flag
3. Given the following HA cluster setup snippet in ha-config.yaml:
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
controlPlaneEndpoint: "lb.example.com:6443"
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs
What does the controlPlaneEndpoint specify in this configuration?
medium
A. The IP address of the worker node
B. The port for kubelet communication
C. The DNS name of the pod network
D. The load balancer address for master nodes

Solution

  1. Step 1: Understand controlPlaneEndpoint role

    This field defines the address (usually a load balancer) that routes traffic to the master nodes in an HA setup.
  2. Step 2: Analyze options

    The load balancer address for master nodes correctly identifies it as the load balancer address. Other options do not relate to controlPlaneEndpoint.
  3. Final Answer:

    The load balancer address for master nodes -> Option D
  4. Quick Check:

    controlPlaneEndpoint = load balancer address [OK]
Hint: controlPlaneEndpoint points to the HA load balancer [OK]
Common Mistakes:
  • Confusing it with worker node IP
  • Thinking it is pod network DNS
  • Mixing it with kubelet port
4. You tried to join a new master node to your HA cluster using this command:
kubeadm join lb.example.com:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:12345
But it failed with an error about missing --control-plane flag. What is the correct fix?
medium
A. Remove the token from the command
B. Add the --control-plane flag to the join command
C. Use kubeadm init instead of join
D. Change the port number to 8080

Solution

  1. Step 1: Identify the error cause

    Joining a master node requires the --control-plane flag to indicate it is a control plane node.
  2. Step 2: Apply the fix

    Add --control-plane to the join command to fix the error.
  3. Final Answer:

    Add the --control-plane flag to the join command -> Option B
  4. Quick Check:

    Joining master needs --control-plane flag [OK]
Hint: Joining master nodes requires --control-plane flag [OK]
Common Mistakes:
  • Removing token breaks authentication
  • Using init instead of join for adding nodes
  • Changing port to wrong value
5. You want to set up a Kubernetes HA cluster with 3 master nodes behind a load balancer. Which of the following steps is the correct order to achieve this?
hard
A. Set up load balancer -> Initialize first master with kubeadm and config -> Join other masters with --control-plane -> Join worker nodes
B. Initialize all masters separately -> Set up load balancer -> Join worker nodes
C. Join worker nodes -> Initialize first master -> Set up load balancer -> Join other masters
D. Set up load balancer -> Join worker nodes -> Initialize all masters

Solution

  1. Step 1: Set up load balancer first

    The load balancer must be ready to route traffic to masters before initializing the cluster.
  2. Step 2: Initialize first master with kubeadm and config

    This creates the cluster control plane and configures the controlPlaneEndpoint.
  3. Step 3: Join other masters with --control-plane flag

    Other masters join as control plane nodes to form HA.
  4. Step 4: Join worker nodes

    Finally, worker nodes join the cluster to run workloads.
  5. Final Answer:

    Set up load balancer -> Initialize first master with kubeadm and config -> Join other masters with --control-plane -> Join worker nodes -> Option A
  6. Quick Check:

    Load balancer first, then masters, then workers [OK]
Hint: Load balancer first, then init masters, then join workers [OK]
Common Mistakes:
  • Initializing all masters before load balancer
  • Joining workers before masters
  • Skipping --control-plane flag on masters