How to Setup Cluster Using kops On AWS EC2

You must have aws cli installed on your server and an access key and secret key with admin access permission in it and it should be configured on your ec2 instance, for doing this execute the below command:-

sudo apt-get install awscli

Setup Cluster

Now configure you awscli (it’s a part of AWS, if you are new to AWS, please refer our AWS tutorial section) by entering your access key and your secret key along with the region(where your ec2 instance is running), after that it will ask for the output format which is optional with default value of json but here we are explicitly using json just for demo purpose after that you are all set to create a cluster in kubernetes on AWS.

aws configure

configure aws cli

You also need to install docker on the server and login to your docker registry, for installing docker use the command below

sudo apt install -y

After that login to your docker registry

sudo docker login


KOPS installation in AWS::
KOPS – Kubernetes Operations

1. Launch Ubuntu based instance to execute below commands to install kops.

2. Kops binary download

curl -LO$(curl -s | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64

chmod +x kops-linux-amd64

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

3. Create an IAM user with admin permissions and make a note of access key & security key and then create S3 bucket and enable versioning.


4. Kubectl installation (K8s cli).

sudo apt-get update && sudo apt-get install -y apt-transport-https 
curl -s | sudo apt-key add -

echo "deb kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list 
sudo apt-get update

sudo apt-get install -y kubectl

5. Now create a ssh key for creating cluster it will act as a pem file for accessing your master and nodes server and it is also essential for creating your kubernetes cluster, for creating it execute the below command:-

ssh-keygen -f .ssh/id_rsa

6. Setting up of Environment variables – Cluster name should always end with k8s.local. Update .bashrc and .profile in ~dir with these two variables.

Cluster name should end with .k8s.local and if you have your own domain then provide it at the end of your cluster name instead of .k8s.local

export KOPS_CLUSTER_NAME=<cluster name> 
export KOPS_STATE_STORE=s3://s3-bucket-name

After this restart your bash rc . ~/.bashrc.

7. Create cluster:: — This will actually prepare the configuration files.

kops create cluster \
--node-count=1 \
--node-size=t2.micro \
--master-size=t2.micro \
--zones=us-east-1a \

If you want to create your cluster without associating public ip to your master as well as worker nodes, then execute the below command

kops create cluster \
  --node-count=1 \
  --zones=us-east-1a \
  --node-size=t2.micro \
  --master-size=t2.micro \
  --master-zones=us-east-1b \
  --networking=weave \
  --topology=private \
  --name=${KOPS_CLUSTER_NAME} \

(optional) if you wanted to review & edit the cluster configuration:

kops edit cluster --name ${KOPS_CLUSTER_NAME}

RUN if you’re okay with the configuration run the command with –yes as like below:

kops update cluster --name ${KOPS_CLUSTER_NAME} --yes

Output shows like below..

Cluster is starting.	It should be ready in a few minutes.


    • validate cluster: kops validate cluster
    • list nodes: kubectl get nodes --show-labels
    • ssh to the master: ssh -i ~/.ssh/id_rsa admin@api.salesforcedrillers.k8s.local
    • the admin user is specific to Debian. If not using Debian please use the appropriate user based on your OS.
    • read about installing addons at:

To validate the cluster::

kops validate cluster

8. Deploying dashboard feature.
The Dashboard UI is not deployed by default. To deploy it, run the following command:

kubectl apply -f

To access it you need to enable command line proxy.

kubectl proxy

Kubectl will make Dashboard available at.


9. To get admin user’s password::

kops get secrets kube --type secret -oplaintext

You will get a password on your screen like this


10. Token generation for admin:

kops get secrets admin --type secret -oplaintext 


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

NOTE:- For allowing kubernetes to pull image from your docker private registry you need to provide the credentials path to kubernetes so that it should read the docker config.json other it will show error failed to pull images from your registry, to overcome this issue execute the below command.

kubectl create secret generic regcred \
    config.json> \
Subscribe Now