AWS and Kubernetes

AWS and Kubernetes (simple setup using kops)

kops is a command line tool that helps you create Kubernetes clusters. AWS (Amazon Web Services) is currently officially supported, with GCE in beta support. The following instructions are for installing and running kops on a Linux box. It assumes you have an AWS account and credentials (Access Key and Secret Key).

Installing kops

Install kops cli

wget -O kops 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
sudo mv ./kops /usr/local/bin/

Install aws cli

pip install awscli
aws configure

Setup variables for an AWS bucket name and region

Change the values below to meet your criteria

export BUCKETNAME=YOUR_BUCKET_NAME # examples: my-kops-system-state or kops-cluster-state, etc...
export REGION=YOUR_REGION_NAME # examples: us-east-2, or us-west-1, etc...

Install kubectl

wget -O 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

Create a bucket first

aws mb s3://${BUCKETNAME} --region ${REGION}

Setup env variables (probably should add theses to your .bash_profile)

export NAME=myfisrtcluster.k8s.local # gossip based (ends in k8s.local)
export KOPS_STATE_STORE=s3://${BUCKETNAME}

Create a keypair for login to the cluster

ssh-keygen -t rsa

Get AZ info

aws ec2 describe-availability-zones --region ${REGION}

Reference: https://github.com/kubernetes/kops/blob/master/docs/commands.md#other-interesting-modes

Choose Availability Zones from the REGION you want the cluster deployed into – change the sizes, number of nodes, etc… The --target is optional, you will get a CloudFormation template placed into the out/ directory

Create the cluster and send output to CF file in out/ dir

kops create cluster --zones=us-east-2a,us-east-2b ${NAME} --node-count=2 --node-size=t2.small --master-zones=us-east-2a --master-size=t2.medium --target=cloudformation

Run the CloudFormation stack or just proceed to the edit command

Nothing is deployed until you edit the config

kops edit cluster ${NAME}

Build the cluster

kops update cluster ${NAME} --yes

Cluster should be up

kubectl get nodes
kops validate cluster
kubectl -n kube-system get pods

Reference: https://github.com/kubernetes/dashboard

Installing the dashboard

The dashboard provides a GUI interface into the cluster

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

Get username and password

kubectl config view

Run the cluster-info command to get the cluster url

kubectl cluster-info

Login with username and password found when you ran the kubectl config view command

Get a token so you can authenticate with the dashboard

kubectl get secrets

Find the default secret

kubectl describe secret PAST_YOUR_SECRET_VALUE

Copy secret token value and enter it in the dashboard

Cleanup

Cleanup by deleting the cluster

kops delete cluster --name ${NAME}

Review resources to be deleted

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

Removes resources, cleans the bucket, but does not delete it

 

Michael Hayslip

 

Leave a Reply

Your email address will not be published. Required fields are marked *