Skip to content

A terraform and kops implementation of a kubernetes cluster

Notifications You must be signed in to change notification settings

DPeterK/our-kubernetes

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Our Kubernetes

Requirements

brew install kops terraform kubernetes-helm kubectl

Create the cluster

Create required infrastructure with terraform

To create a kubernetes cluster with kops you need a few bits of infrastructure already in place. This includes an IAM user for kops to use, a DNS zone for routing, an S3 bucket to store config, etc. This can be created simply using the terraform scripts.

# Run the terraform
terraform apply terraform

Create the kubernetes components with kops

Now we can create the cluster itself.

# Export AWS Environment vars
export AWS_ACCESS_KEY_ID=$(terraform output k8s-access-key-id)
export AWS_SECRET_ACCESS_KEY=$(terraform output k8s-secret-access-key)

# Export kops vars
# _you should probably add these to your .bashrc/.zshrc but you might want to
# hard code the values rather than pointing to the terraform output_
export KOPS_CLUSTER_NAME="cluster.$(terraform output k8s-dns-zone)"
export KOPS_STATE_STORE="s3://$(terraform output k8s-state-bucket)"

# Generate the cluster config (this gets stored in the S3 bucket)
kops create cluster --cloud aws --zones eu-west-2a ${KOPS_CLUSTER_NAME}

# Check config and make any modifications to the scaling groups etc
kops edit cluster ${KOPS_CLUSTER_NAME}

# Start the cluster, a kops update ensures the AWS infrastructure matches the config
kops update cluster ${KOPS_CLUSTER_NAME} --yes

Create cluster services

Go through each of the services in cluster-services and install as per the README.md there.

Create pod disruption budgets

Install the pod disruption budgets as per pod-disruption-budgets/README.md.

Connect to an existing cluster

If a cluster already exists you can retrieve the kubectl config by setting the KOPS_CLUSTER_NAME and KOPS_STATE_STORE vars and then running the following command.

export KOPS_CLUSTER_NAME="cluster.k8s.informaticslab.co.uk"
export KOPS_STATE_STORE="s3://informticslab-k8s-config"
kops export kubecfg --name ${KOPS_CLUSTER_NAME}

You should then be able to use kubectl. For example you can list the namespaces.

kubectl get ns

About

A terraform and kops implementation of a kubernetes cluster

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HCL 52.6%
  • Dockerfile 47.4%