Test project to create a game of tic tac toe, while also learning how to use kubernetes and docker.
- Tools Required
- Set up docker environment on windows
- Start Minikube
- Create a docker image for the tictactoe application
- Deploy postgres
- Deploy application
-
Java with Spring boot
-
Docker toolbox
-
Minikube
-
Postgresql DB
-
Postman
-
HTML
- Download Docker ToolBox and install.
https://docs.docker.com/toolbox/toolbox_install_windows/
- Download and Install kubernetes and minikube.
https://kubernetes.io/docs/tasks/tools/install-minikube/
- Start minikube using command
start minikube
- Configure shell to use docker commands
@FOR /f "tokens=*" %i IN ('minikube docker-env') DO @%i
-
Create a dockerfile.
-
From the root directory of the project (The one with pom.xml), build the code.
mvn clean install
- Build the docker image specifying the tag and version.
docker build -t tictactoe:latest
- Pull postgres image and deploy.
kubectl run postgres --image=postgres:latest --env="POSTGRES_PASSWORD=postgres" --image-pull-policy=IfNotPresent
- Expose postgres deployment on desired port.
kubectl expose --port=5432 deployment postgres --type=NodePort
- (Optional) Check if service is running and get postgres service url.
minikube service postgres --url
- Deploy the application, set the port to match tomcat port as configured in the application.
kubectl run tictactoe --image=tictactoe:latest --port=8087 --image-pull-policy=IfNotPresent
- Expose the application deployment.
kubectl expose deployment tictactoe --type=NodePort
- Get the application's service URL.
minikube service tictactoe --url
Now the containers can be accessed by using docker ip in browser