Skip to content

Latest commit

 

History

History
95 lines (62 loc) · 1.86 KB

README.md

File metadata and controls

95 lines (62 loc) · 1.86 KB

Kubernetes with Express

Create Docker Container

This docker container runs a basic Express server at port 3000. The dependencies are installed using pnpm package manager.

Build docker image

docker build -t <image_name> .

Notes:

  1. --t - Name and optionally a tag in the name:tag format

Run a container to test the image

docker run --rm -d -p <desired_port>:<express_port> <image_name>

Notes:

  1. --rm - Automatically remove the container when it exits
  2. -d - Make the container runs in the background and print the container ID
  3. -p - Publish a container's port(s) to the host

To view running containers

docker ps

To stop a specific container from running

docker stop <container_id>

To push image to Docker hub

docker push <docker_hub_username>/<image_name>:<tag>

Note:

  1. Make sure you run docker login first before perform the docker push command
  2. If no :<tag> defined, the tag defaults to latest

Create Kubernetes Cluster

Requirement

  1. Minikube
  2. kubectl

Create Kubernetes Deployment and Service definition

Refer kube/deployment-service.yaml

Start Minikube

minikube start

Create Deployment and Service on Kubernetes cluster

kubectl apply -f kube/deployment-service.yaml

Check components created in Kubernetes cluster

kubectl get all

Run Kubernetes cluster

  1. Get the service name using the command below. In this repo case is basic-express-k8s-service
kubectl get svc
  1. Then, run the minikube command as below:
minikube service <service_name>

References

  1. https://www.digitalocean.com/community/tech-talks/how-to-deploy-a-resilient-node-js-application-on-kubernetes-from-scratch
  2. https://www.tomray.dev/nestjs-docker-production