Deploy your application using Kubernetes
This document provides a comprehensive guide for deploying the GoFast application onto new servers using Kubernetes. The deployment strategy involves building Docker images, pushing them to the GitHub Container Registry (GHCR), and then deploying these images to a Kubernetes cluster.
This guide explains how to set up two separate systems:
release
)release-candidate
)You’ll need to follow this guide’s steps twice: once for release
and once for release-candidate
. Each will use different settings.
The ultimate aim is to establish a fully automated CI/CD pipeline leveraging GitHub Actions. This pipeline will automatically build, test, and deploy the GoFast application based on the type of GitHub Release created:
v1.0.0
) in the GitHub repository triggers a deployment to the release
(production) environment.v1.0.0-rc.1
) triggers a deployment to the release-candidate
(staging) environment.The guide is structured into two main phases: setting up the Kubernetes cluster and configuring the GitHub Actions CI/CD pipeline.
Important: Run all commands from the kube
directory.
Ensure the following tools are installed:
You’ll need a server with root access, accessible via SSH:
12.34.56.78
)Set up domains/subdomains:
user.gofast.live
)admin.gofast.live
)client.gofast.live
)grafana.gofast.live
)These domains should resolve to the corresponding server IP addresses:
Include AAAA records if using IPv6.
You have two options to set the environment variables:
.env
file with your secrets.This script will:
The deployment will fail, because we didn’t build the images yet. The CI/CD pipeline will handle this automatically in the next step.
In your GitHub repository, navigate to Settings > Environments and click ‘New environment’ to create two environments:
release
for production environmentrelease-candidate
for staging environmentMake sure you are using the correct context:
Paste the kubeconfig file into the KUBE_CONFIG
secret.
Save these secrets and GitHub environment variables in the GitHub repository:
DB_NAME
, DB_USER
, DB_PASSWORD
PRIVATE_KEY_PEM
and PUBLIC_KEY_PEM
(generated using scripts/keys.sh
)Modify the .github/workflows/release.yml
to match your environments and services.
Ensure the image names used when running kube/setup.sh
match those defined in the .github/workflows/release.yml
file.
With the setup complete, the CI/CD pipeline will automatically build the images and deploy them to the Kubernetes cluster. To trigger a deployment, create a new Release or Pre-release in your GitHub repository, as detailed in the Overview.
For the Next.js and Vue.js clients, we need to update the build environment variables.
IAM & Admin > Service Accounts
, and create a service account with the Cloud SQL Client
role.kube/gcp-sa-key.json
. Add the key to your GitHub repository secrets as GCP_SA_KEY
.Cloud SQL Admin API
.Cloud SQL > Instances
, create a new instance, and select PostgreSQL
as the database type.DB_NAME
, DB_USER
, and DB_PASSWORD
respectively.project-id:region:instance-name
) as CLOUD_SQL_CONNECTION_NAME
.kube/setup.sh
- Uncomment the Google Cloud SQL secrets and comment the CloudNativePG secrets.kube/config/service-user.yaml
- Uncomment the Google SQL Proxy configuration..github/workflows/migration.yml
- Uncomment the Google Cloud SQL section and comment the CloudNativePG section.Deploy your application using Kubernetes
This document provides a comprehensive guide for deploying the GoFast application onto new servers using Kubernetes. The deployment strategy involves building Docker images, pushing them to the GitHub Container Registry (GHCR), and then deploying these images to a Kubernetes cluster.
This guide explains how to set up two separate systems:
release
)release-candidate
)You’ll need to follow this guide’s steps twice: once for release
and once for release-candidate
. Each will use different settings.
The ultimate aim is to establish a fully automated CI/CD pipeline leveraging GitHub Actions. This pipeline will automatically build, test, and deploy the GoFast application based on the type of GitHub Release created:
v1.0.0
) in the GitHub repository triggers a deployment to the release
(production) environment.v1.0.0-rc.1
) triggers a deployment to the release-candidate
(staging) environment.The guide is structured into two main phases: setting up the Kubernetes cluster and configuring the GitHub Actions CI/CD pipeline.
Important: Run all commands from the kube
directory.
Ensure the following tools are installed:
You’ll need a server with root access, accessible via SSH:
12.34.56.78
)Set up domains/subdomains:
user.gofast.live
)admin.gofast.live
)client.gofast.live
)grafana.gofast.live
)These domains should resolve to the corresponding server IP addresses:
Include AAAA records if using IPv6.
You have two options to set the environment variables:
.env
file with your secrets.This script will:
The deployment will fail, because we didn’t build the images yet. The CI/CD pipeline will handle this automatically in the next step.
In your GitHub repository, navigate to Settings > Environments and click ‘New environment’ to create two environments:
release
for production environmentrelease-candidate
for staging environmentMake sure you are using the correct context:
Paste the kubeconfig file into the KUBE_CONFIG
secret.
Save these secrets and GitHub environment variables in the GitHub repository:
DB_NAME
, DB_USER
, DB_PASSWORD
PRIVATE_KEY_PEM
and PUBLIC_KEY_PEM
(generated using scripts/keys.sh
)Modify the .github/workflows/release.yml
to match your environments and services.
Ensure the image names used when running kube/setup.sh
match those defined in the .github/workflows/release.yml
file.
With the setup complete, the CI/CD pipeline will automatically build the images and deploy them to the Kubernetes cluster. To trigger a deployment, create a new Release or Pre-release in your GitHub repository, as detailed in the Overview.
For the Next.js and Vue.js clients, we need to update the build environment variables.
IAM & Admin > Service Accounts
, and create a service account with the Cloud SQL Client
role.kube/gcp-sa-key.json
. Add the key to your GitHub repository secrets as GCP_SA_KEY
.Cloud SQL Admin API
.Cloud SQL > Instances
, create a new instance, and select PostgreSQL
as the database type.DB_NAME
, DB_USER
, and DB_PASSWORD
respectively.project-id:region:instance-name
) as CLOUD_SQL_CONNECTION_NAME
.kube/setup.sh
- Uncomment the Google Cloud SQL secrets and comment the CloudNativePG secrets.kube/config/service-user.yaml
- Uncomment the Google SQL Proxy configuration..github/workflows/migration.yml
- Uncomment the Google Cloud SQL section and comment the CloudNativePG section.