Cloud Computing

Kubernetes tutorial – Create Kubernetes cluster on AWS with kops

This is in continuation of Kubernetes article series. In the earlier posts, we have seen how to create & deploy a simple cluster. Now in this post, we are going to look at how to provision Kubernetes cluster using kops utility. For more posts on Kubernetes, check out here & here.

kops (Kubernetes Operations) helps you create, destroy, upgrade and maintain production-grade, highly available, Kubernetes clusters from the command line. Some of the key features are listed below:

  • Automates the provisioning of Kubernetes clusters in AWS and GCE
  • Deploys Highly Available (HA) Kubernetes Masters
  • Uses DNS to identify clusters
  • Self-healing: everything runs in Auto-Scaling Groups
  • Limited OS support (Debian preferred, Ubuntu 16.04 supported, early support for CentOS & RHEL)
  • Supports custom Kubernetes add-ons
  • YAML Manifest Based API Configuration
  • Can directly provision, or generate terraform manifests

This quickstart assumes a basic understanding of Kubernetes concepts, please refer earlier posts for understanding on Kubernetes & how to create, deploy & rollout updates to the cluster.

Step #1.kops Installation

I’m using Linux so here are the commands to get kops, for other releases/ platform you can find it here.

wget -O kops https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64 
chmod +x ./kops 
sudo mv ./kops /usr/local/bin/

Image – Install kops CLI

Step #2.kubectl installation

Download the latest release with the command:

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
Image – kubectl Installation

Make the kubectl binary executable.

chmod +x ./kubectl

Move the binary in to your PATH.

sudo mv ./kubectl /usr/local/bin/kubectl

To check what are the available kubectl commands,run kubectl from the terminal

$ kubectl
kubectl controls the Kubernetes cluster manager.

Find more information at https://github.com/kubernetes/kubernetes.

Basic Commands (Beginner):
  create         Create a resource from a file or from stdin.
  expose         Take a replication controller, service, deployment or pod and
expose it as a new Kubernetes Service
  run            Run a particular image on the cluster
  set            Set specific features on objects
  run-container  Run a particular image on the cluster. This command is
deprecated, use "run" instead

Basic Commands (Intermediate):
  get            Display one or many resources
  explain        Documentation of resources
  edit           Edit a resource on the server
  delete         Delete resources by filenames, stdin, resources and names, or
by resources and label selector

Deploy Commands:
  rollout        Manage the rollout of a resource
  rolling-update Perform a rolling update of the given ReplicationController
  scale          Set a new size for a Deployment, ReplicaSet, Replication
Controller, or Job
  autoscale      Auto-scale a Deployment, ReplicaSet, or ReplicationController

Cluster Management Commands:
  certificate    Modify certificate resources.
  cluster-info   Display cluster info
  top            Display Resource (CPU/Memory/Storage) usage.
  cordon         Mark node as unschedulable
  uncordon       Mark node as schedulable
  drain          Drain node in preparation for maintenance
  taint          Update the taints on one or more nodes

Troubleshooting and Debugging Commands:
  describe       Show details of a specific resource or group of resources
  logs           Print the logs for a container in a pod
  attach         Attach to a running container
  exec           Execute a command in a container
  port-forward   Forward one or more local ports to a pod
  proxy          Run a proxy to the Kubernetes API server
  cp             Copy files and directories to and from containers.
  auth           Inspect authorization

Advanced Commands:
  apply          Apply a configuration to a resource by filename or stdin
  patch          Update field(s) of a resource using strategic merge patch
  replace        Replace a resource by filename or stdin
  convert        Convert config files between different API versions

Settings Commands:
  label          Update the labels on a resource
  annotate       Update the annotations on a resource
  completion     Output shell completion code for the specified shell (bash or
zsh)

Other Commands:
  api-versions   Print the supported API versions on the server, in the form of
"group/version"
  config         Modify kubeconfig files
  help           Help about any command
  plugin         Runs a command-line plugin
  version        Print the client and server version information

Use "kubectl  --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all
commands).

Step #3.Create new IAM User on AWS Console

Login to AWS Console, In the navigation pane, choose Users and then choose Add user to create new user with Programmatic access. This is the user kops would connect and store the cluster state information.

Alternatively, you can also create the IAM user from the command line using AWS CLI tools.

Image – Create new user for kops

Set following IAM permissions for the kops user & click on Next

  • AmazonEC2FullAccess
  • AmazonRoute53FullAccess
  • AmazonS3FullAccess
  • IAMFullAccess
  • AmazonVPCFullAccess
Image – Set user permissions

Review permissions & Click Next

Image – Review Permissions

User creation successful, record Access key ID & Secret access key. We would be using them in the next step.

Image – User creation successful

Run the below commands to set the environment variables

export AWS_ACCESS_KEY_ID=<replace with your access key>
export AWS_SECRET_ACCESS_KEY=<replace with your secret key>

Step #4.Create new s3 bucket to store cluster information

In order to store the state of your cluster, and the representation of your cluster, we need to create a dedicated S3 bucket for kops to use. This bucket will become the source of truth for our cluster configuration.

Image – Create S3 Bucket to store cluster information

Enter bucket name & click Next,Enable Versioning for production environment if in case you ever need to revert or recover a previous state store.

Image – S3 Bucket created

To recap,we have installed kubectl,kops utilities,created new IAM user and s3 bucket to hold cluster information. We are now ready to create our 1st cluster.

Step #5.Create cluster

Run the below commands to set the environment variables

export NAME=k8cluster.k8s.local <replace appropriately>
export KOPS_STATE_STORE=s3://kubernetes-upnxt-aws-io <replace appropriately>

Here NAME indicates the cluster name, make sure it ends with k8s.local and KOPS_STATE_STORE is the s3 bucket location.

Image – Set environment variables for Cluster name & State store

Next, step is to create cluster configuration. Make sure that you have generated SSH key pair before creating the cluster.

kops create cluster \
    --zones us-west-2a \
    ${NAME}

Here zones refers to which region/zone you would want to create the cluster. This is the basic example of creating cluster, more examples can be found here.

Image – kops create cluster command

Once the cluster is created, you can use kubectl to view and interact with the cluster. As you can see, the cluster has been created with 1 master & 1 worker node.

Image – kubectl get nodes to view the cluster

Congrats! our Kubernetes cluster is online and working.

Next,  if you’re planning to deploy or update the application, you can follow the same set of steps as described in the earlier posts.

As a last step, if you want to delete the cluster that we created above use below command.

kops delete cluster --name ${NAME} --yes

 

Like this post? Don’t forget to share it!

Additional Resources

Summary
Article Name
Kubernetes tutorial - Create Kubernetes cluster on AWS with kops
Description
kops (Kubernetes Operations) helps you create, destroy, upgrade and maintain production-grade, highly available, Kubernetes clusters from the command line.In this post we are going to look at how to provision Kubernetes cluster on AWS using kops utility.
Author
Publisher Name
upnxtblog
Publisher Logo
Karthik

Allo! My name is Karthik,experienced IT professional.Upnxtblog covers key technology trends that impacts technology industry.This includes Cloud computing,Blockchain,Machine learning & AI,Best mobile apps, Best tools/open source libs etc.,I hope you would love it and you can be sure that each post is fantastic and will be worth your time.

Share
Published by
Karthik

Recent Posts

Social Media Marketing: A Key to Business Success with Easy Digital Life

In today's digital-first world, businesses must adopt effective strategies to stay competitive. Social media marketing…

7 hours ago

Best 7 AI Tools Every UI/UX Designer Should Know About

62% of UX designers now use AI to enhance their workflows. Artificial intelligence (AI) rapidly…

2 days ago

How AI Enhances Photoshop Workflow: A Beginner’s Guide

The integration of artificial intelligence into graphic design through tools like Adobe Photoshop can save…

2 weeks ago

The Rise Of Crypto Trading Bots: A New Era In Digital Trading

The cryptocurrency trading world has grown significantly in recent years, with automation playing a key…

3 weeks ago

Real-World Insights on White-Label NFT Marketplace Development

The non-fungible token (NFT) market has witnessed explosive growth over the past few years, transforming…

3 weeks ago

Finding the Right Time to Build Your Software Instead of Buy

There are few things as valuable to a business as well-designed software. Organizations today rely…

1 month ago

This website uses cookies.