Full guide at https://www.gmhafiz.com/blog/deploy-applications-in-kubernetes/
Instructions are in this file.
vim ./db/README.md
cd ..
git clone https://github.com/gmhafiz/k8s-api
cd k8s-api
cat README.md
Set image tag
TAG=$(git rev-parse HEAD)
echo $TAG
docker build -f Dockerfile-api -t gmhafiz/api:$TAG .
docker build -f Dockerfile-migrate -t gmhafiz/migrate:$TAG .
docker push gmhafiz/api:${TAG}
docker push gmhafiz/migrate:${TAG}
kubectl apply -f configmap.yaml
kubectl apply -f server.yaml
kubectl apply -f service.yaml
Edit migrate image
vim migrate-job.yaml
Run migration
kubectl apply -f migrate-job.yaml
View migrate log
kubectl get pods
kubectl logs -f migrate-job-zhmpt
# returns
2023/09/09 02:49:30 starting migrate...
2023/09/09 02:49:30 reading env
2023/09/09 02:49:30 connecting to database...
2023/09/09 02:49:30 database connected
2023/09/09 02:49:30 OK 20230302080119_create_randoms_table.sql (42.53ms)
2023/09/09 02:49:30 goose: no migrations to run. current version: 20230302080119
2023/09/09 02:49:30 goose: version 20230302080119
Port forward
kubectl port-forward --namespace default svc/server 3080:3080
In a new terminal
curl http://localhost:3080/randoms
cd ..
git clone https://github.com/gmhafiz/k8s-web
cd k8s-web
TAG=$(git rev-parse HEAD)
echo $TAG
docker build -t gmhafiz/web:${TAG} .
docker push gmhafiz/web:${TAG}
Change directory
cd k8s-devops/web
Edit image tag
vim web.yaml
# gmhafiz/web:b169cbaecb549b11f5597ef6dd2f7647fd1133cc <--
kubectl apply -f web.yaml
kubectl port-forward svc/web 8080:8080
Go to http://localhost:8080 and enjoy!