Skip to content

Commit caeafd6

Browse files
committed
Add traefik installation to makefile to avoid depending on civo marketplace
1 parent ff4ee38 commit caeafd6

5 files changed

Lines changed: 67 additions & 23 deletions

File tree

12-deploying-containers/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ When we provision a PostgresDB within the project, Railway automatically sets th
2626

2727
## Docker swarm
2828

29+
At this point, we already have a `docker compose` file which allows us to specify our application using a single command. There are a few limitations with docker compose that make it less than ideal to run a production application with docker compose directly:
2930

31+
- No support for secrets (we are passing our DB credentials as environment variables)
32+
- No support for zero downtime re-deployments
33+
34+
Luckily, docker swarm does provide those things and setting up a single node cluster can be done with one command `docker swarm init`. Making just a few modifications to the docker compose file (adding `deploy` configurations, passing sensitive info as secrets and reading those data as files within the applications) it is ready to deploy.
35+
36+
1) Create a virtual machine with your favorite cloud provider. Make sure to set up the firewall to listen on ports 80, 443, and 22.
37+
2) Use the script at https://get.docker.com/ to install docker engine
38+
3) Set the `DOCKER_HOST` environment variable in the Makefile to `USERNAME@IP_ADDRESS` of your virtual machine (this will allow your local docker client to use the remote docker daemon!)
39+
4) Build and push the container images to a registry
40+
5) Populate the secrets by running `make create-secrets`
41+
6) Deploy the application by running `make swarm-deploy-stack` (uses the `docker stack deploy` command under the hood)
42+
7) Set up a DNS A record to route traffic to your VM (or access using the IP address)
3043

3144
## Kubernetes
45+
46+
I was planning to only include the Railway + Swarm examples, but figured a course about containers wouldn't be complete without at least mentioning Kubernetes, the most popular container orchestrator today. Like Docker Swarm, Kubernetes is designed to schedule and run your containers, but has more maturity when it comes to cloud provider support.
47+
48+
I created the necessary resource yaml files in `./kubernetes` to deploy the application. You will notice that it is somewhat more verbose than the swarm specification.
49+
50+
1) Create a kubernetes cluster with your favorite cloud provider.
51+
2) Set up kubectl to connect to the cluster (using the cloud provider instructions)
52+
3) Install Traefik ingress controller by running `make install-traefik` (uses this helm chart https://github.com/traefik/traefik-helm-chart)
53+
4) Install Postgres by running `make install-postgres` (uses this helm chart https://github.com/bitnami/charts/tree/main/bitnami/postgresql)
54+
5) Deploy the application by running `make deploy-app`
55+
6) Set up a DNS A record to route traffic to the IP address of the load balancer that traefik provisions

12-deploying-containers/docker-swarm/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ compose-down:
1515

1616
### DOCKER SWARM
1717

18-
CIVO_SSH:="ssh://ubuntu@212.2.244.220"
18+
DOCKER_HOST:="ssh://ubuntu@212.2.244.220"
1919

2020
.PHONY: swarm-init
2121
swarm-init:
22-
DOCKER_HOST=${CIVO_SSH} docker swarm init
22+
DOCKER_HOST=${DOCKER_HOST} docker swarm init
2323

2424
.PHONY: swarm-deploy-stack
2525
swarm-deploy-stack:
26-
DOCKER_HOST=${CIVO_SSH} docker stack deploy -c docker-swarm.yml example-app
26+
DOCKER_HOST=${DOCKER_HOST} docker stack deploy -c docker-swarm.yml example-app
2727

2828
.PHONY: swarm-remove-stack
2929
swarm-remove-stack:
30-
DOCKER_HOST=${CIVO_SSH} docker stack rm example-app
30+
DOCKER_HOST=${DOCKER_HOST} docker stack rm example-app
3131

3232
.PHONY: create-secrets
3333
create-secrets:
34-
echo -n "foobarbaz" | DOCKER_HOST=${CIVO_SSH} docker secret create postgres-passwd -
35-
echo -n "postgres://postgres:foobarbaz@db:5432/postgres" | DOCKER_HOST=${CIVO_SSH} docker secret create database-url -
34+
echo -n "foobarbaz" | DOCKER_HOST=${DOCKER_HOST} docker secret create postgres-passwd -
35+
echo -n "postgres://postgres:foobarbaz@db:5432/postgres" | DOCKER_HOST=${DOCKER_HOST} docker secret create database-url -

12-deploying-containers/docker-swarm/docker-compose-prod.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ version: '3.7'
33
services:
44
client-react-nginx:
55
image: sidpalas/devops-directive-docker-course-client-react-nginx:5
6-
deploy:
7-
mode: replicated
8-
replicas: 1
9-
update_config:
10-
order: start-first
116
networks:
127
- frontend
138
ports:
@@ -22,11 +17,6 @@ services:
2217
api-node:
2318
image: sidpalas/devops-directive-docker-course-api-node:8
2419
read_only: true
25-
deploy:
26-
mode: replicated
27-
replicas: 1
28-
update_config:
29-
order: start-first
3020
networks:
3121
- frontend
3222
- backend
@@ -47,11 +37,6 @@ services:
4737
api-golang:
4838
image: sidpalas/devops-directive-docker-course-api-golang:7
4939
read_only: true
50-
deploy:
51-
mode: replicated
52-
replicas: 1
53-
update_config:
54-
order: start-first
5540
networks:
5641
- frontend
5742
- backend

12-deploying-containers/kubernetes/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
.PHONY: deploy-traefik
2+
deploy-traefik:
3+
-helm repo add traefik https://traefik.github.io/charts
4+
helm upgrade --install -n traefik --create-namespace -f traefik-values traefik traefik/traefik
5+
16
.PHONY: deploy-postgres
27
deploy-postgres:
3-
helm repo add bitnami https://charts.bitnami.com/bitnami
4-
helm install db bitnami/postgresql --set auth.postgresPassword=foobarbaz
8+
-helm repo add bitnami https://charts.bitnami.com/bitnami
9+
helm upgrade --install db bitnami/postgresql --set auth.postgresPassword=foobarbaz
510

611
.PHONY: deploy-app
712
deploy-app:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Taken from CIVO marketplace values
2+
deployment:
3+
kind: DaemonSet
4+
rbac:
5+
enabled: true
6+
ports:
7+
websecure:
8+
tls:
9+
enabled: true
10+
podAnnotations:
11+
prometheus.io/port: "8082"
12+
prometheus.io/scrape: "true"
13+
providers:
14+
kubernetesIngress:
15+
publishedService:
16+
enabled: true
17+
priorityClassName: "system-cluster-critical"
18+
# Rancher didn't have the latest v2.9.6 image associate with the latest helm chart
19+
# Using the default dockerhub traefik image instead
20+
# image:
21+
# name: "rancher/mirrored-library-traefik"
22+
tolerations:
23+
- key: "CriticalAddonsOnly"
24+
operator: "Exists"
25+
- key: "node-role.kubernetes.io/control-plane"
26+
operator: "Exists"
27+
effect: "NoSchedule"
28+
- key: "node-role.kubernetes.io/master"
29+
operator: "Exists"
30+
effect: "NoSchedule"

0 commit comments

Comments
 (0)