aisbaa / aws-eks-example

AWS EKS (Elastic Kubernetes Service) example.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AWS EKS Example

This is a shortened version of the Get Started.

  • No manual operation from the Management Console.
  • CFn stacks merged into one.
  • 2 public subnets and 2 private subnets (with NAT gateways).
  • Worker nodes launch into private subnets.
  • Renamed some files and resources.

Install tools

  1. Download kubectl and heptio-authenticator-aws to current directory.
  2. Upgrade to latest AWS CLI.

Deploy stack

$ aws cloudformation deploy --template-file cfn.yml --capabilities CAPABILITY_IAM --stack-name eks-example

Configure kubectl

$ aws cloudformation describe-stacks --stack-name eks-example --query Stacks[0].Outputs

Edit k8s-config.yml and k8s-configmap-aws.yml.

Then, set KUBECONFIG.

$ export KUBECONFIG=k8s-config.yml

Join nodes to the cluster

$ ./kubectl apply -f k8s-configmap-aws.yml
$ ./kubectl get nodes
NAME                                       STATUS    ROLES     AGE       VERSION
ip-10-0-12-27.us-west-2.compute.internal   Ready     <none>    26s       v1.10.3
ip-10-0-9-187.us-west-2.compute.internal   Ready     <none>    29s       v1.10.3

Cool.

Deploy some sample apps

For instance, WordPress.

Define storage class

Before claiming a persistent volume, you need to define an EBS storage class and set it default.

$ ./kubectl apply -f k8s-storageclass-ebs-gp2.yml
$ ./kubectl get storageclass
NAME            PROVISIONER             AGE
gp2 (default)   kubernetes.io/aws-ebs   13s

Storage Classes - Amazon EKS

Deploy

$ ./kubectl create secret generic mysql-pass --from-literal=password=THEMOSTSECUREPASSWORDEVER
$ ./kubectl create -f https://github.com/kubernetes/website/raw/master/content/en/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/mysql-deployment.yaml

This operation creates an EBS volume for persistent volume.

$ ./kubectl create -f https://github.com/kubernetes/website/raw/master/content/en/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/wordpress-deployment.yaml

And this operation creates a load balancer.

$ ./kubectl describe services wordpress

Ta-da!

You can access the load balancer's DNS name and you'll see the WP initial setting page!

Clean up

$ ./kubectl delete secret mysql-pass
$ ./kubectl delete deployment -l app=wordpress
$ ./kubectl delete service -l app=wordpress
$ ./kubectl delete pvc -l app=wordpress
$ aws cloudformation delete-stack --stack-name eks-example

About

AWS EKS (Elastic Kubernetes Service) example.