DEV Community

Prithiviraj R
Prithiviraj R

Posted on

Setting 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

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
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

Image description

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more