Installing Kubernetes on AWS with kops

Installing Kubernetes could be a tedious and error-prone process. Intead of setting up every thing in the hard way, you might want to use kops to facilate the installation if you are planning to build your Kubernetes cluster on AWS.

Just follow most of instructions on the pages Installing Kubernetes on AWS with kops and aws.md to install k8s then you should good to go.

Here are some of my suggestions on the installation.

Try unreleasd version of kops

If you encounter issues setting up a cluster, or you want to setup latest version of kubernetes (becasue the development timeline of kops is usally fall behind kubernetes), you can install the unreleased version (HEAD) of kops by homebrew on you Mac.

$ brew update && brew install --HEAD kops

Please refer to README for other ways to install kops.

Use the latest release of kubectl

If you don’t have specific requirement sticking to the older version of kubernetes, it’s usually a better idea to use the latest one since it’s more stable and has more features.

Similarily, you can install kubectl via homebrew.

$ brew update && brew install kubectl

Update your nameserver

Because most of kops operations do DNS lookup for NS records for you domain, if it cannot get the informaiton, it show an error like this

error doing DNS lookup for NS records for "dev.example.com": lookup dev.example.com on 192.168.0.1:53: no such host

On my mac, I tried to update the nameserver list in /etc/resolv.conf to solve the issue.

#
# Mac OS X Notice
#
# This file is not used by the host name and address resolution
# or the DNS query routing mechanisms used by most processes on
# this Mac OS X system.
#
# This file is automatically generated.
#
search dev.example.com
# use Google's DNS server instead
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 192.168.0.1

Specify Kubernetes version

You can specify the version of kubernetes by --kubernetes-version argument of create cluster command.

$ kops create cluster --zones ap-northeast-1a,apnortheast-1c --kubernetes-version v1.5.1 apnortheast.k8s.linkernetworks.com

Change to a custom image to create instances

By default, Kops use debain AMI to spin up nodes. If you would like to change to a custom image (AMI), just edit the configuration of nodes instance group before kops actually creates the cluster.

# $ kops edit ig --name=$CLUSTER_NAME nodes

apiVersion: kops/v1alpha2
kind: InstanceGroup
metadata:
  creationTimestamp: "2017-01-04T16:27:43Z"
  name: nodes
spec:
  associatePublicIp: true
  image: ${IMAGE_NAME}
  machineType: t2.medium
  maxSize: 2
  minSize: 2
  role: Node
  subnets:
  - ap-northeast-1a

Type the command aws ec2 describe-images --image-id ami-XXXXX To find out the image name.

images.md has more information about the configurations of applying custom images.

Note that you can always update the spec of you instance group after the creation of the cluster.

Customized the cluster and instance group specs

Follow up above section, you are free to customize the spec of the cluster and instance group. For example, you can adjust the minimum number of alived instances, the root volume size, and the machine type of instances in a instance group.

apiVersion: kops/v1alpha2
kind: InstanceGroup
metadata:
  creationTimestamp: "2017-01-04T16:27:43Z"
  name: nodes
spec:
  associatePublicIp: true
  image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21 
  machineType: m3.2xlarge # setting the machine type.
  maxSize: 2
  minSize: 1  # setting the minimum number of alived instances.
  role: Node
  subnets:
  - ap-northeast-1a
  rootVolumeSize: 100 # setting root volume size to 100GB.

More information could be found in cluster_spec.md and instance_groups.md

Verify the installation

Wait for few minutes after you issue the command kops update cluster $CLUSTER_NAME --yes, then validate the cluster via validate command.

$ kops validate cluster apnortheast.k8s.linkernetworks.com

# Validating cluster apnortheast.k8s.linkernetworks.com
# 
# INSTANCE GROUPS
# NAME      ROLE  MACHINETYPE  MIN  MAX  SUBNETS
# master-ap-northeast-1a  Master  m3.medium  1  1  ap-northeast-1a
# nodes      Node  t2.medium  2  2  ap-northeast-1a
# 
# NODE STATUS
# NAME              ROLE  READY
# ip-172-20-37-26.ap-northeast-1.compute.internal    node  True
# ip-172-20-58-48.ap-northeast-1.compute.internal    master  True
# ip-172-20-59-130.ap-northeast-1.compute.internal  node  True
# 
# Your cluster apnortheast.k8s.linkernetworks.com is ready

Kops helps you to create all sorts of AWS resources required to setup kubnertes cluster. You can verify them in different AWS services.

Domain created in Route 53
Domain created in Route 53
Configurations of the Kubernetes cluster are stored in S3
Configurations of the Kubernetes cluster are stored in S3
Two auto-scaling groups for master and nodes
Two auto-scaling groups for master and nodes
One master node and two worker nodes
One master node and two worker nodes