Tuesday, January 14, 2025

Setting Up a Kubernetes Cluster with KOPS

Programming LanguageSetting Up a Kubernetes Cluster with KOPS


Introduction
Kops (Kubernetes Operations) is a command-line tool that simplifies the deployment, upgrade, and management of Kubernetes clusters. It is often considered the “kubectl” equivalent for cluster operations and is best suited for production-grade clusters.

This guide walks you through the process of creating a Kubernetes cluster using Kops.

Step 1: Prerequisites
Install AWS CLI

https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
Enter fullscreen mode

Exit fullscreen mode

Configure it:

aws configure

Enter fullscreen mode

Exit fullscreen mode

Install kubectl

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/

Enter fullscreen mode

Exit fullscreen mode

Install Kops

curl -LO https://github.com/kubernetes/kops/releases/download/v1.28.0/kops-linux-amd64
chmod +x kops-linux-amd64
sudo mv kops-linux-amd64 /usr/local/bin/kops

Enter fullscreen mode

Exit fullscreen mode

Image description

Set up an S3 bucket for Kops state storage

aws s3api create-bucket --bucket <your-kops-state-store> --region <region> --create-bucket-configuration LocationConstraint=<region>

Enter fullscreen mode

Exit fullscreen mode

Enable versioning

aws s3api put-bucket-versioning --bucket <your-kops-state-store> --versioning-configuration Status=Enabled

Enter fullscreen mode

Exit fullscreen mode

Set environment variables

Define the Kops state store

export KOPS_STATE_STORE=s3://<your-kops-state-store>
Enter fullscreen mode

Exit fullscreen mode

Step 2: Create a Cluster

kops create cluster \
  --name=<cluster-name> \
  --state=$KOPS_STATE_STORE \
  --zones=<availability-zones> \
  --node-count=<number-of-nodes> \
  --node-size=<instance-type> \
  --master-size=<instance-type> \
  --dns-zone=<hosted-zone-name>
Enter fullscreen mode

Exit fullscreen mode

Image description

Image description

Validate the configuration
Ensure the cluster configuration is correct:

kops update cluster --name <cluster-name> --yes

Enter fullscreen mode

Exit fullscreen mode

Access the cluster
Retrieve the Kubernetes config and interact with the cluster:

kubectl get nodes
Enter fullscreen mode

Exit fullscreen mode

Image description

Clean Up
To delete the cluster when it is no longer needed:

kops delete cluster --name <cluster-name> --yes

Enter fullscreen mode

Exit fullscreen mode

Happy Learning

Prithiviraj Rengarajan
DevOps Engineer

Check out our other content

Check out other tags:

Most Popular Articles