Kubernetes Installation Using KOPS (1.6.1) on AWS

I am quite new for Docker and Kubernetes world. I have been playing with dockers past few months, and I strongly believe that Containers are the deployment format for future.Docker really make it much easier to package an application with its required infrastructure.We need a tool to take care of things such as replication and failovers, as well as APIs to automate deployments to multiple machines.

Kubernetes seems to be the best choice, since it was being backed by Google, Red Hat, Core OS, and other groups that clearly know about running large-scale deployments.

I came across a number of blogs which using Kubernetes old versions and installation method like Kube-up which is deprecated, hence, I am writing this blog to help beginners like me who would be interested in exploring Kubernetes.

I am going to use KOPS(kubernetes Ops) 1.6.1 to install Kubernetes.

Find github project.

Below are the prerequisites for set up on AWS

  1. AWS account
  2. Subdomain on Route53.

Download kops :

#wget https://github.com/kubernetes/kops/releases/download/1.6.1/kops-linux-amd64
#sudo chmod +x kops-linux-amd64
#sudo mv kops-linux-amd64 kops
#sudo mv kops /usr/local/bin/
#sudo apt-get install python-pip
#sudo pip install awscli
#aws configure

Here you have to provide access and secret keys, default region and output format(json,yaml).

Then create S3 bucket to store meta data.

#aws s3 mb s3://kops-sarancloud // Bucket name should be unique.

Download Kubectl

#curl -O https://storage.googleapis.com/kubernetes-release/release/v1.6.1/bin/linux/amd64/kubectl
#sudo mv kubectl /usr/local/bin
#sudo chmod +x /usr/local/bin/kubectl

Create ssh key to login into servers.

#ssh-keygen -f .ssh/id_rsa

Now its time to create cluster.

#kops create cluster --name=kubernetes.awsdevopsblog.solutions --state=s3://kops-sarancloud --zones="ap-southeast-1a,ap-southeast-1b" --node-count=1 --node-size=t2.micro --master-zones=ap-southeast-1a   --master-size=t2.micro --dns-zone=kubernetes.awsdevopsblog.solutions --ssh-public-key=~/.ssh/id_rsa.pub

Note: By default, it launched debian 8 and use default user “admin”. You can ssh via pubic IP only. If you need to ssh with private IP then you need to use — topology=private, — networking=weave and — bastion=”true” in kops create command.

Where name is my sub domain and state is s3 bucket name. It will launch one master and two nodes.

Output will have more numbers of line. At the end you can see something like below:

Finally configure your cluster with: kops update cluster kubernetes.awsdevopsblog.solutions — yes

We can edit the cluster with below command :

#kops edit cluster kubernetes.awsdevopsblog.solutions --yes --state=s3://kops-sarancloud

Before update the cluster we have to create secret keys for ssh into the master and node servers.

kops create secret --name kubernetes.awsdevopsblog.solutions sshpublickey admin -i ~/.ssh/id_rsa.pub --state=s3://kops-sarancloud

Finally, give below command to setup cluster.

#kops update cluster kubernetes.awsdevopsblog.solutions --yes --state=s3://kops-sarancloud

After few times, one master and two nodes will be launched in your AWS account.

Now you can use kubectl to get info about your nodes.

#kubectl get node

Now, will deploy default nginx in docker containers.

#kubectl run my-nginx --image=nginx --replicas=2 --port=80
#kubectl get pods
#kubectl get deployment

Expose pods to internet.

#kubectl expose deployment my-nginx --port=80 --type=LoadBalancer
#kubectl get services

Set up Kubernetes Dashboard.

#kubectl create -f https://s3-ap-southeast-1.amazonaws.com/kops-sarancloud/v1.6.1.yaml

Default username will be “admin”, but password we have to retrieve form s3 bucket.

#kops get secrets kube --type secret -oplaintext --state=s3://kops-sarancloud

Dashboard URL will be https://api.<clustername>/ui.

In my case : https://api.kubernetes.awsdevopsblog.solutions/ui

You can see deployment and services.

Access nginx with ELB endpoint.

Use below command to delete the cluster.

#kops delete cluster kubernetes.awsdevopsblog.solutions --yes --state=s3://kops-sarancloud

Happy Learning. Enjoy !! :)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.