AWS Kubernetes Installation with KOPS: Godin Technologies

Emmanuelibok
6 min readJul 9, 2023

--

What is Kops?

Kops is a command-line utility for controlling Kubernetes clusters. The Kubernetes community created it to make it easier to deploy and manage production-ready Kubernetes clusters on cloud infrastructure providers like Amazon Web Services (AWS), Google Cloud Platform (GCP), and others.

Users can declare the intended state of their Kubernetes clusters using Kops’ declarative configuration syntax. It manages the underlying infrastructure provisioning, such as virtual machine creation, networking configuration, and storage resource setup. Kops also handles the initialization of Kubernetes control plane components such as etcd, kube-Episerver, kube-controller-manager, and kube-scheduler.

Users can quickly establish, update, and delete Kubernetes clusters with Kops, as well as expand the cluster size and handle rolling upgrades for cluster components. It works well with other Kubernetes tools and ecosystem components, allowing users to take advantage of Kubernetes’ full power for container orchestration and administration.

Prerequisites:

  1. Creating ubuntu ec2 instance in AWS
  2. Install AWS CLI
  3. Install Kops software on the Ubuntu instance
  4. Install kubectl
  5. Creating an IAM role from Aws console pr CLI with the below policies
  6. Create an s3 bucket and execute the below command in kops serve use a unique bucket name if you get the bucket name
  7. Create ssh keys before creating a cluster
  8. Create Kubernetes cluster definitions on the s3 bucket
  9. Create Kubernetes cluster
  10. Validate your cluster
  11. To list nodes
  12. To delete cluster

1. Creating ubuntu ec2 instance in AWS

1.Log in to the AWS Management Console as follows: Sign in to the AWS Management Console (https://console.aws.amazon.com/) with your AWS credentials.

2. Once logged in, travel to the EC2 Dashboard by searching for “EC2” in the AWS services search field or by selecting EC2 from the list of services.

3. Launch Instance: To begin the instance creation process, click the “Launch Instance” button in the EC2 Dashboard.

4. Select the appropriate version of Ubuntu from the available options in the “Step 1: Choose an Amazon Machine Image (AMI)” section. You can, for example, select “Ubuntu Server 20.04 LTS” or any other Ubuntu version. Once you’ve decided, press the “Select” button.

5. Select an Instance Type: In the “Step 2: Choose an Instance Type” section, select the instance type that best meets your requirements. In terms of CPU, memory, storage, and network capabilities, the instance kinds differ. Choose an instance type that meets your needs, and then click “Next: Configure Instance Details.”

6. Configure Instance Details: In this area, you can change the number of instances, the network settings, and the storage options. You can leave most of the default settings alone or tweak them as needed. When you’re finished customizing, select “Next: Add Storage”.

7. Add Storage: Specify the size and kind of storage for your instance here. If necessary, you can add more volumes. Adjust the storage options to meet your needs, then click “Next: Add Tags.”

8. Tags are key-value pairs that can be added to instances to improve organization and administration. Tags can be used to help identify your instance. “Next: Configure Security Group” should be selected.

9. Configure Security Group: In this part, you can configure your instance’s security group. A security group serves as a virtual firewall for your instance, regulating both inbound and outbound traffic. You have the option of selecting an existing security group or creating a new one. Configure the security group rules to meet your requirements. Once completed,

10. Instance Launch: Go over all of your instance’s configuration details. Check that everything is in order. If any changes are required, return to the relevant stages and make the necessary adjustments. After you’ve double-checked everything, press the “Launch” button.

11. Key Pair: In this stage, you will be asked whether you want to use an existing key pair or create a new one. SSH key pairs are used to securely connect to your instance. Select a suitable selection and then press the “Launch Instances” button.

12. Launch Status: A confirmation message will appear confirming that your instances are being launched. To access the Instances view, click the “View Instances” button.

2. Install AWS CLI

Commands to be run,

sudo apt update -y

sudo apt install unzip wget -y

sudo curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -O awscli-bundle.zip

sudo apt install unzip python -y

sudo unzip awscli -bundle.zip

sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/bin/local/aws

3. Install Kops software on the Ubuntu instance

Commands to be run,

sudo apt install wget -y

sudo wget https://github.com/kubernetes/kops/release/download/v1.16.1/kops-linux-amd64

sudo chmod +x kops-linux-amd64

sudo mv kops-linux-amd64 /usr/local/bin/kops

4. Install kubectl

Run this commands on your Ubuntu terminal,

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

sudo chmod +x ./kubectl

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

was s3 mb s3://godintech1.k8s.local

aws s3 ls

5. Creating an IAM role from Aws console pr CLI with the below policies

by AOS Note

my blog:https://medium.com/@emmanuelibok505/how-to-set-up-an-aws-command-line-interface-cli-profile-for-an-iam-user-772b942956f

(i).AMAZONEC2FULLACCESS

(ii).AMAZONS3FULLACCESS

(iii). IAMFULLACCESS

(iv).AMAZONVPCFULLACCESS

Attach the IAM role to the Ubuntu server from the console, select the key →attach/replace the IAM role →select the role which you created → save.

6. Create an s3 bucket and execute the below command in kops serve use a unique bucket name if you get the bucket name

aws s3 mb s3://godintech.k8s.local

aws s3 ls

EX.

# S3 bucket name should be unique across aws

aws s3 mb ://godintech.k8s.local

s3://godintech.k8s.local

Expose environmental variables:

# Add environmental variables in bashrc

vi. bashrc

# Give unique name and s3 bucket you created

export NAME=godintech.k8s.local

export KOPS_STATE_STORE=s3://godintech.k8s.local

source.bashrc

7. Create ssh keys before creating a cluster

ssh-keygen

8. Create Kubernetes cluster definitions on s3 bucket

(i)kops create cluster __zones us-east-1a __networking weave master-size t2.medium __master-count2 __node-size t2.large __count=3 ${NAME}

(ii)kops create cluster __zones us-east-1b __networking weave master-size t2.medium __master-count3 __node-size t2.large __count=5 ${NAME}

(iii)kops create secret __name ${NAME} __yes

9. Create a Kubernetes cluster

kops update cluster ${Name} __yes

10.Validate your cluster -(kops will take sometime to create cluster,execute command after 3 or 4 mins.)

kops validate cluster

11. To list nodes

kubectl get nodes

12. To delete the cluster

kops delete cluster __name= ${NAME} __state = ${KOPS_STATE_STORE} __yes

13. If you want ssh to Kubernetes master or nodes created by Kops. You can ssh from Kops server.

ssh -i -/.ssh/id_rsa admin@<IPorDNS>

Conclusion:

Kops is a command-line utility designed to control Kubernetes clusters on cloud infrastructure providers like Amazon Web Services (AWS) and Google Cloud Platform (GCP). It manages infrastructure provisioning, virtual machine creation, networking configuration, and storage resource setup. Kops also handles the initialization of Kubernetes control plane components, such as etcd, kube-Episerver, kube-controller-manager, and kube-scheduler. Users can establish, update, and delete Kubernetes clusters with Kops, as well as expand the cluster size and handle rolling upgrades for cluster components.

To create a Kubernetes cluster, follow these steps:

1. Log in to the AWS Management Console with your AWS credentials.
2. Navigate to the EC2 Dashboard and select “EC2” from the list of services.
3. Launch an instance by clicking the “Launch Instance” button in the EC2 Dashboard.
4. Select an Amazon Machine Image (AMI) version and click “Select.”
5. Select an instance type and click “Next: Configure Instance Details.”
6. Configure Instance Details, including the number of instances, network settings, and storage options.
7. Add Storage and configure the Security Group.
8. Launch Instances and verify the configuration details.
9. Create a Kubernetes cluster by running the following commands:

1. Create an IAM role from the AWS console using the following policies:

1. Create an S3 bucket with a unique bucket name.
2. Create SSH keys before creating a cluster.
3. Create Kubernetes cluster definitions on the S3 bucket.
4. Validate the cluster.

In summary, Kops is a powerful command-line utility for controlling Kubernetes clusters on cloud infrastructure providers like AWS and GCP. It simplifies the process of creating, updating, and deleting clusters, allowing users to leverage Kubernetes’ full power for container orchestration and administration.

The audience is appreciated!

I’m always open to feedback, so please comment below.

--

--

Emmanuelibok

As a DevOps pro, I automate workflows, boost reliability, and foster teamwork. My goal: agile, secure, and efficient software delivery.