This Kubernetes project was edited by Mr. Nicolas Muller in parallel with the Treeptik learning platform.
Firstname : Charley Lastname : GEOFFROY Filiere : DO3 Year : 2022-2023
This project is a Kubernetes project that will be used to deploy a frontend, a backend and a database. The frontend will be a SSR application using Next.js, the backend will be a REST API using Express and the database will be a Postgres database.
A CI github actions is configured to build the docker images and push them to the github registry. The images are then pulled from the registry and deployed on the Kubernetes cluster.
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-$(uname)-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kindAdd autocomplete to kind by editing your ~/.bashrc file and adding the following line:
source <(kind completion bash)kind create cluster tp-kubeFor each namespace you want to create, you can use the following command (frontend, backend, db):
kubectl create namespace <namespace>For each deployment you want to create, you can adapt the following command in the appropriate working directory, this will create a deployment.yaml file that you can adapt and apply:
kubectl create deploy <deployment-name> --image=<image> -n <namespace-required> --dry-run=client -o yaml > deployment.yamlFor each service you want to create, you can adapt the following command in the appropriate working directory, this will create a service.yaml file that you can adapt and apply:
kubectl create service <service-type> <service-name> --tcp=<port>:<port> -n <namespace-required> --dry-run=client -o yaml > service.yamlFor each secret you want to create, you can adapt the following command in the appropriate working directory, this will create a secret.yaml file that you can adapt and apply:
kubectl create secret generic <secret-name> --from-literal=<key>=<value> -n <namespace-required> --dry-run=client -o yaml > secret.yamlkubectl create -R -f infra/nsFrom the working directory, you can apply this command to apply all kubernetes objects:
kubectl apply -R -f infra/You can also delete all kubernetes objects:
kubectl delete -R -f infra/To apply specific objects, you can use the following command:
kubectl apply -f <object-name>.yamlkubectl port-forward services/webapp-service 5000:80 -n frontendThen you can access on heathcheck page on ==> localhost:5000/healthz
In order to access the backend API, the frontend sends a request to backend-service.backend.svc.cluster.local:5000 you can find the serverRuntimeConfig in the frontend/next.config.js file.