Skip to content

openupthecloud/k8s-starter-eks-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The purpose of this repo is to give you a very minimal EKS cluster for the purpose of learning Kubernetes using Terraform. The cluster is a great foundation for starting to learn what it might take to manage a production-ready Kubernetes cluster in AWS on EKS, deployed through Terraform. The starter is intentionally a minimal starter, and is not an entirely production-ready cluster (e.g. no remote state for terraform setup, the single node setup is insufficient, etc). The starter, however is a great jumping off point to start to iterate on the given configuration to add your own complexity and features yourself.

image

Prerequisite knowledge

You do not need to be a master of all of the below technologies, but you do at least need to know what they are, what they do, and be comfortable modifying them if you need to debug anything. For instance, if you have never deployed an EC2 instance into AWS using Terraform (or a similar tool), that would be a better starting point than this repository.

  1. Linux - Installing packages, configuring environment variables and configuration files, using commands, flags, etc.
  2. AWS Compute & Networking Foundations - e.g. EC2, Subnets, VPC.
  3. Kubernetes - Understanding of the reasons for using Kubernetes, and basic terminology.

Related Documentation

This repository is based on the following documentation:

Getting Started

Requires at least 1 t2.medium instance to run the required containers and the workload.

Step 1: Install dependencies (AWS, Terraform, Kubectl)

./install.sh

Step 2: Deploy the infrastructure with Terraform

Update VPC default in ./variables.tf

terraform apply

Or pass it as the vpc ID variable:

terraform apply -var vpc_id=$(aws ec2 describe-vpcs | jq -r .Vpcs[0].VpcId)

Step 3: Connect KubeCTL to the deployed cluster

aws eks update-kubeconfig --region us-east-1 --name my-cluster-eks

Step 4: Create an app with a deployment and service

kubectl apply -f app.yaml

FAQs

Why not create the cluster manually?

By using Terraform we can easily create and destroy our infrastructure repeatedly. It's hard sometimes using the AWS interface to know what you really did, or what was deployed. It would not be wise in a production environment to use this "ClickOps" approach, so we avoid that practice here, and start with a foundation that can scale towards production-ready.

Why not use EKSCTL?

Terraform is a widely adopted tool that works across a lot more technology than just Kubernetes. If the rest of your infrastructure in AWS is defined in Kubernetes, it would make sense to deploy your cluster in Terraform to take advantage of connecting features such as Terraform outputs, etc. Terraform also gives you a lot of fine-grained control. At some point, abstractions like EKSCTL start to break down. Starting with Terraform from the beginning avoids the need to migrate to Terraform or a more flexible provisioning tool later. Don't believe me, see this StackOverflow thread.

Why not use minikube, kind, or other local Kubernetes tools?

The local K8s replication tools are useful for learning the terminology behind Kubernetes, however they will not allow you to see how it feels to run a Kubernetes cluster in a more production environment. A managed service like EKS abstracts some of the control plane concerns away so there is a lower complexity, however the abstractions with other native cloud services such as EC2, Load Balancers etc are useful to understand and cannot be learned through a local Kubernetes emulation tool.

How can I see what is running in my cluster when deployed?

kubectl get pods -n eks-sample-app kubectl get all -n eks-sample-app

How can I debug my deployed service?

You can access your running pod or service by running:

kubectl exec -it <deployment-id> -n eks-sample-app -- /bin/bash

For example:

kubectl exec -it eks-sample-linux-deployment-5b568bf897-5xkf7 -n eks-sample-app -- /bin/bash

How can I visualise what is deployed in the terraform module?

Running terraform state show will show you the list of resources inside your module once deployed. Using terraform graph you can also export your graph to a tool like: https://edotor.net/ to visualise the infra. However, be careful not to share any sensitive information contained in your state file(s) with external or 3rd parties.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published