Skip to content

Makefiles for creating and deploying to a DigitalOcean-hosted Kubernetes cluster.

Notifications You must be signed in to change notification settings

benjaminbergstein/kubernetes-deploy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kubernetes-deploy

Makefiles for creating and deploying to a DigitalOcean-hosted Kubernetes cluster.

Contents

Prerequisites

Dependencies

The following dependencies are required:

  • doctl - Digital Ocean CLI (install info).
  • kubectl - Kubernetes command-line tool (install info)
  • envsubst - Linux tool for templating using environment variables (more info), if your system does not ship with it.

Authorization

In addition to downloading doctl and kubectl, you need to authorize against against your DigitalOcean account

The authenticate and authorize targets may suffice for connecting to DigitalOcean's Kubernetes and Docker Registry offerings.

Usage

This project contains a set of make targets for managing a Kubernetes cluster and its deployments.

Make targets

Create cluster

CLUSTER_NAME=your-cluster-name make -C cluster deploy

Destroy cluster

CLUSTER_NAME=your-cluster-name make -C cluster destroy

Authenticate

Configure kubectl command to connect to your cluster.

CLUSTER_NAME=your-cluster-name make -C cluster authenticate

Authorize

Create secrets to allow your cluster to pull from DigitalOcean's docker registry.

CLUSTER_NAME=your-cluster-name make -C cluster authorize

Deploy

Create a new deployment at ./deployment, or follow the "Hello, World" example below and modify to your needs.

PROJECT=your-deployment-name make -C deployment deploy

Destroy deployment

PROJECT=your-deployment-name make -C deployment destroy

"Hello, World" example

This example uses the hashicorp/http-echo image to run a Kubernetes services that responds to HTTP requests with the text "hello world".

Before completing this example you will need to install dependencies, create a Kubernetes cluster on DigitalOcean, and authorize your local kubectl client to access the cluster. Follow documentation above.

Create the deployment

Run the following command:

$ PORT=8080 PROJECT=example DOCKER_IMAGE=hashicorp/http-echo make -C deployment deploy
rm example/production.yaml
envsubst < example/template.yaml > example/production.yaml
kubectl apply -f example/production.yaml
deployment.apps/example-production configured
service/example-production-lb configured

Ensure pod successfully started:

$ kubectl get pods
NAME                                  READY   STATUS    RESTARTS   AGE
example-production-57b9c4bc5c-4tbfr   1/1     Running   0          14m

Wait for LoadBalancer

Run the following command:

kubectl get services

The EXTERNAL-IP field will display as pending. Wait for the load balancer to have an EXTERNAL-IP. Once it does, you can navigate to that IP address in your browser.

You can also get the IP address with this one-liner:

$ kubectl get service example-production-lb | grep -v NAME | awk '{print $4}'
161.0.0.1
Hello World Example

Cleanup

To destroy this deployment, run the following command:

$ PROJECT=example make -C deployment destroy
kubectl delete -f example/production.yaml
deployment.apps "example-production" deleted
service "example-production-lb" deleted

About

Makefiles for creating and deploying to a DigitalOcean-hosted Kubernetes cluster.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published