Software Development

Set up Kubernetes on AWS

“Kubernetes is an open-source container-orchestration system for automating deployment, scaling and management of containerized applications”

The goal of this step by step memo is to get a Kubernetes Cluster formed by a Master and 2 or more nodes up and running on AWS using Kops.

A) Install Prerequisites

  1. Install Kubernetes-cli using chocolately: choco install kubernetes-cli
  2. Install Aws-cli
  3. Configure Aws-cli with your credentials: aws configure
  4. Create an S3 bucket to store the state for Kops. I usually use eu-west-2 but you can set your favourite zone
    • aws s3api create-bucket --bucket es01-kops-state-store --region eu-west-2 --create-bucket-configuration LocationConstraint=eu-west-2
    • Enable versioning for the S3 bucket: aws s3api put-bucket-versioning --bucket es01-kops-state-store --versioning-configuration Status=Enabled
  5. Download Kops from https://github.com/kubernetes/kops/releases

Notes: I usually use Windows for software development. I run Kops commands using an executable called “kops-windows-amd64”. On Linux or Mac you can just use “kops” instead and the rest is the same. To install Kops on Mac just use: brew update && brew install kops. The version for windows is quite new and in beta at the time that I’m writing. I renamed the downloaded file kops-windows-amd64 to kops.exe. To run the commands open a command line and cd in the folder where kops is (or set a env variable to use it from anywhere).

B) Create the Kubernetes Cluster

Kubernetes Operations (kops) – Production Grade K8s Installation, Upgrades, and Management.

Kops is a tool to create, upgrade and maintain Kubernetes clusters on AWS but it also works with Google cloud and other providers.

In this guide, I’m using Kops to create the Kubernetes Cluster but there are other options available. Almost all Cloud Providers like Azure or AWS are offering similar features. At the moment I still prefer to not use one of the Cloud specific services and that’s why I’m using Kops instead.

  1. Create the cluster:
      • kops create cluster --node-count=3 --master-size=t2.medium --node-size=t2.micro --zones=eu-west-2a --name=es01.k8s.local --state=s3://es01-kops-state-store
      • kops update cluster --name es01.k8s.local --yes

    Note: if you get permission errors when you use kops you probably need to set the state-store name as environment variables or pass it in your commands. Kops also share the context and credential of Aws cli and therefore it’s important configure it properly.

  2. Validate cluster and wait for ‘ready’ status
    • kops validate cluster --state=s3://es01-kops-state-store
  3. Install the Kubernetes dashboard
    • kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
  4. Access the Dashboard using the Url: https://<master-node-url>/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login
    • To get your <master-node-url> run the command: kubectl cluster-info
    • User name is admin
    • To get the password run the command: kops get secrets kube --type secret -oplaintext
    • To get the Token run the command: kops get secrets admin --type secret -oplaintext
  5. (optional) Install a monitoring add-on for autoscaling and nicer stats on dashboard
    • kubectl create -f https://raw.githubusercontent.com/kubernetes/kops/master/addons/monitoring-standalone/v1.7.0.yaml
    • kops edit ig nodes
    • The above command opens the cluster config. Change the Max Size and save changes
    • kops update cluster --name es01.k8s.local --yes

Now you have a Kubernetes cluster up and running.

To destroy it and delete almost all its resources, run the following command:
kops delete cluster --name es01.k8s.local --yes