Simple Kubernetes Deployment Using kops

Part I : Deploying Kubernetes Cluster to AWS

Image for post
Image for post

Hand’s ON

Create Cluster

$ curl -LO 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-linux-amd64
$ sudo mv kops-linux-amd64 /usr/local/bin/kops
$ curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
$ chmod +x ./kubectl
$ sudo mv ./kubectl /usr/local/bin/kubectl
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install
# configure the aws client to use the IAM user
$ aws configure # Use user access and secret key here
$ aws iam list-users      # If all goes well you should list of your IAM users here
# create bucket
$ aws s3api create-bucket \
--bucket prefix-example-com-state-store \
--region us-east-1
# enbale versioning
$ aws s3api put-bucket-versioning \
--bucket prefix-example-com-state-store \
--versioning-configuration Status=Enabled \
# enbale encryption
$ aws s3api put-bucket-encryption \
--bucket prefix-example-com-state-store \
--server-side-encryption-configuration \
'{"Rules":[{"ApplyServerSideEncryptionByDefault": \
{"SSEAlgorithm":"AES256"}}]}'
# save the bucket name as env variable
# consider to put this in .bashrc or .profile
$ export KOPS_STATE_STORE=s3://prefix-example-com-state-store
# consider to put this in .bashrc or .profile
$ export NAME=myfirstcluster.example.com
# consider to put this in .bashrc or .profile
$ export NAME=myfirstcluster.k8s.local
$ aws ec2 describe-availability-zones --region us-west-1
# I create one master node (t3.medium) and 2 worker nodes (t3.micro)
distributed in multiple zones.
$ kops create cluster \
--name ${NAME} \
--zones us-west-1b,us-west-1c \
--master-zones us-west-1b \
--node-count=2 \
--node-size=t3.micro \
--master-size=t3.medium \
--cloud-labels "Team=Dev,Owner=John Doe"
# after creating cluster it will ask you about ssh key to access the nodes so create one if you haven't
$ ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa
$ kops create secret sshpublickey admin -i ~/.ssh/id_rsa.pub
--name{NAME} --state ${KOPS_STATE_STORE}
# then update to finalize everything
$ kops update cluster --name ${NAME} --yes
$ kops validate cluster
$ kubectl get nodes
Image for post
Image for post

Update Cluster

kops edit ig master-us-west-1b --name ${NAME}
kops edit ig nodes --name ${NAME}
$ kops update cluster --yes
$ kops rolling-update cluster --yes

Install Metric Server

$ kops edit cluster# add the following
kubelet:
anonymousAuth: false
authorizationMode: Webhook
authenticationTokenWebhook: true
# apply the changes
$ kops update cluster --yes
$ kops rolling-update cluster --yes
# If you use Kubernetes 1.16+
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/kops/master/addons/metrics-server/v1.16.x.yaml
$ kubectl top nodes
Image for post
Image for post

Delete Cluster

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

Written by

Coffee & Technology Enthusiast

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