Makefiles for creating and deploying to a DigitalOcean-hosted Kubernetes cluster.
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.
In addition to downloading doctl and kubectl, you need to authorize against against your DigitalOcean account
- How to log in to
doctlwith your DigitalOcean account - How to authorize
kubectlto access your DigitalOcean account usingdoctl
The authenticate and authorize targets may suffice for connecting to DigitalOcean's Kubernetes and Docker Registry offerings.
This project contains a set of make targets for managing a Kubernetes cluster and its deployments.
CLUSTER_NAME=your-cluster-name make -C cluster deployCLUSTER_NAME=your-cluster-name make -C cluster destroyConfigure kubectl command to connect to your cluster.
CLUSTER_NAME=your-cluster-name make -C cluster authenticateCreate secrets to allow your cluster to pull from DigitalOcean's docker registry.
CLUSTER_NAME=your-cluster-name make -C cluster authorizeCreate a new deployment at ./deployment, or follow the "Hello, World" example below and modify to your needs.
PROJECT=your-deployment-name make -C deployment deployPROJECT=your-deployment-name make -C deployment destroyThis 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.
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$ kubectl get pods
NAME READY STATUS RESTARTS AGE
example-production-57b9c4bc5c-4tbfr 1/1 Running 0 14mRun the following command:
kubectl get servicesThe 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 |
|---|
![]() |
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