Playground to learn deployment a web service on a cluster. For more details and motivation, check my post
Make sure you have a Google Cloud Platform (GCP) account and then:
GCP provides 300$ free budget for new users.
- Create a project
- Enable Google Kubernetes Engine (GKE).
- Enable Google Container Registry (GCR).
Then:
- Install Go
- Install Terraform CLI.
- Install Kubernetes CLI
- Install Google Cloud CLI
Login to your GCP account through gcloud
:
gcloud auth application-default login
Configure Docker to access private registry:
gcloud auth configure-docker
Before you start, make sure you set variables according to your project in variables.tf
cd <PROJECT_DIRECTORY>
terraform init
terraform apply
This may take a while. After your cluster is created,
gcloud container clusters get-credentials <CLUSTER_NAME>
This will set kubectl to access your cluster. To verify:
kubectl cluster-info
kubectl create secret docker-registry gcr-access-token \
--docker-server=eu.gcr.io \
--docker-username=oauth3accesstoken \
--docker-password="$(gcloud auth print-access-token)" \
[email protected]
make hello-push-image
kubectl apply -f definitions/hello
We start with deploying databases that we use, and then deploy TODO service.
- Create a persistent volume
kubectl apply -f definitions/postgre/pg-pv.yaml
- Create a persistenv volume claim
kubectl apply -f definitions/postgre/pg-pvc.yaml
- Create PostreSQL Deployment
kubectl apply -f definitions/postgre/pg-deployment.yaml
- Create PostgreSQL Service
kubectl apply -f definitions/postgre/pg-service.yaml
- Verify if it works properly:
kubectl get pods
If the status of the pod with name postgres is running, then it works properly.
- Use secrets for password protection
kubectl create secret generic pg-password \
--from-literal=password=<YOUR_PASSWORD>
- Create config map
kubectl apply -f definitions/redis/redis-configmap.yaml
- Create Redis Deployment
kubectl apply -f definitions/redis/redis-deployment.yaml
- Create Redis Service
kubectl apply -f definitions/redis/redis-service.yaml
- Build and push Docker image
make todo-push-image
kubectl apply -f definitions/todo