- Install Docker Desktop for Windows and Enable 'Use the WSL2 based engine..'
- Enable Kubernetes in Docker Desktop
- Install command line tools in WSL2
- To build the container run the following
docker build . -t hello-docker-nodejs
- Above lists the container id. Launch the container using the id
docker run -p 3000:3000 f5ec8a4a7ce2
-
Visit the website using browser or run curl command.
-
Stop docker (from another window)
docker ps
docker stop <container id>
-
Prune everything... (CAUTION.. below removes everything from Docker including other projects and images). Do it only if needed...
docker system prune -a
-
Get existing pods
kubectl get pod
- Get information about all running pods -
Create pod for the hello world nodejs app
kubectl create -f kubernetes/helloworld.yml
Note: imagePullPolicy
should be set to Never
which forces kubernetes to use local image
- Create a service using command line for now.
kubectl port-forward hello-docker-node 8080:3000
And test it by visiting localhost:8080 (curl or browser). ^C to exit the command line afterwords
- Expose the service
kubectl expose pod hello-docker-node --type=NodePort --name=hello-docker-node-service
The service is exposed. It will chose a random port from local host to forward the traffic to above container. Obtain the IP addres by runningkubectl get services
Visit localhost:31828. Note that the port will be different and it is obtained from the kubectl get services command.
- Get more information about the service as follows
kubectl describe service hello-docker-node-service
kubectl describe pod <pod>
kubectl expose pod <pod> --port=3000 --name=frontend
- Creates a service
kubectl port-forward <pod> 8080
- Port forward the exposed pod port to your local machine
kubectl attach <pod> -i
- Attach to pod
kubectl exec <pod> command
- Execute a command on the pod
Use kind: ReplicationController and provide replicas: n to create n number of pods
kubectl create -f helloworld-repl-controller.yml
kubectl get replicationController
or kubectl get rc
kubectl scale --replicas=4 rc/helloworld-controller
Delete the replication controller by
kubectl delete rc/helloworld-controller