Kubernetes Using KOPS

This article is mainly focused on how we set up the Kubernetes cluster on aws cloud using the kops command utility.

Outline

  • Setup Host Environment
  • Prerequisites for cluster creation
  • Creation of Cluster & validation
  • Setup Nginx Ingress Controller
  • Cleanup Cluster

Setup Host Environment

Consider Host machine is linux and follow below steps,

setup kubectl

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectlchmod +x ./kubectlsudo mv ./kubectl /usr/local/bin/kubectl

setup KOPS

download binary files in your local from below link,

chmod +x kops-linux-amd64mv kops-linux-amd64 /usr/local/bin/kopsaws cli setuppip install awscli — upgrade — user

Prerequisites for cluster creation

create new IAM user with below attach policy to create cluster,

AmazonEC2FullAccess

AmazonRoute53FullAccess

AmazonS3FullAccess

AmazonVPCFullAccess

IAMFullAccess

Configure AWS CLI tools with below commands,

aws configure

Create hosted zone ,

aws route53 create-hosted-zone — name digivillage.in — caller-reference 1

Create S3 buckets for storage

aws s3 mb s3://demo-kops

Now set few variables before creating cluster,

export KOPS_STATE_STORE=s3://demo-kops

Creation of Cluster & validation

kops create cluster — zones=us-east-1a,us-east-1b,us-east-1c — node-count=2 — node-size=t3.small — master-size=t3.micro — master-count=1 dev.digivillage.inkops update cluster dev.digivillage.in — yes — admin

SECOND WAY to create

First ,create a yaml configuration file

kops create cluster — name=digivillage.in \- zones=us-east-1a,us-east-1b,us-east-1c \- node-count=2 \- node-size=t3.small \- master-size=t3.micro \- master-count=1 \- dns-zone=digivillage.in \- dry-run \-oyaml > digivillage.in

Second,

kops create cluster — zones=us-east-1a,us-east-1b,us-east-1c — node-count=2 — node-size=t3.small — master-size=t3.micro — master-count=1 — name=digivillage.in — filename digivillage.in

Third,

kops create secret — name digivillage.in sshpublickey admin -i ~/.ssh/id_rsa.pub

// i have use my local system public key you can use other as well

Fourth,

kops update cluster — name digivillage.in — yes — admin

After creation, complete the instructions which are on your terminal.

Now run below command ,

kops export kubecfg dev.yourdomain.com

Then

Validate cluster

kops validate cluster — wait 10m

Then,

kubectl get nodes

List cluster

kops get cluster

NOTE: Below 3 commands varies as per your environment,

Edit Cluster

kops edit cluster dev.digivillage.in

Edit MasterNode

kops edit ig master-us-east-1a — name=dev.digivillage.in

Edit Node

kops edit ig master-us-east-1a — name=dev.digivillage.in

Setup Nginx Ingress Controller

kubectl apply — dry-run -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.27.0/deploy/static/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.27.0/deploy/static/mandatory.yaml
kubectl get pods — all-namespaces
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.27.0/deploy/static/provider/cloud-generic.yaml

Now LoadBalancer service is deployed

Check,

kubectl get service -n ingress-nginx

Sometime it takes time to assign public ip check once again in few seconds,

Once the EXTERNAL-IP is assigned, the NGINX Ingress Controller is ready to serve.

Now,Deploy demo nginx

get the yml files related from

Deploy it now by using below command,

kubectl apply -f demo-nginx.yml

Check the svc of deployment

Kubectl get svc

Next, setup ingress rule to access demo-nginx service,

get the yml files from below link

Now deploy ,

kubectl apply -f demo-ingress.yml

Copy the EXTERNAL-IP of the nginx-demo service into the browser to verify

Edit route53 record like below snapshot or you can create new record as well.

Click on save button.

Now hit in browser with domain name

Cleanup Cluster

kops delete cluster dev.digivillage.in --yes

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hardik Patel

Hardik Patel

Devops Engineer | AWS | Azure | CKA