This is a simple .NET REST API application running on a local kubernetes cluster. To demonstrate how you can run your docker images locally.
To run this application you must have installed on your machine the following tools:
After everything installed, you just have to run the following commands:
Note: Execute everything on the root of this project (the same folder as this README file).
- Build the .NET REST API docker image(make sure docker is running on your machine):
docker build -t guid-api ./src/GuidGenerator.API
To check if the image was created just type:
docker images
And see if there's a image named guid-api
.
To run the container on Docker run:
docker run -it --rm -p 5000:80 --name my-guid-generator-container guid-api
- Create the cluster:
kind create cluster
And type again the command docker images
, to see if the cluster was created. But, on this time, search for a kindest/node
image.
- Load the docker image created before inside the cluster:
kind load docker-image guid-api
- Apply the kubernetes policy to the cluster, for the cluster knows how to behave.
kubectl apply -f kubernetes/manifest.yaml
This might take a while, to see when its read type the following:
To see if the cluster was deployed successfully:
kubectl get deploy
And this to see if the pods are running. A pod is an instance of your application (docker image created on this case).
kubectl get pods
If both shows ready
your application is ready to go. If not, and spent a significant time, may something is broken (must probably on the kubernetes manifest).
To see the log of the .NET application, type:
kubectl logs deploy/guid-api
- You cannot access the application yet, because is pointing to a port on localhost inside the cluster. You must point to a port on the localhost of your machine:
kubectl port-forward service 3000:80
Now, if you access the ``http://localhost:3000/```, you application is running!.