Skip to content

Latest commit

 

History

History
148 lines (111 loc) · 3.09 KB

README.md

File metadata and controls

148 lines (111 loc) · 3.09 KB

k8s-express-js

Creating a k8s cluster w/ minikube

All instructions on creating a deployment (k8s) of a nodejs app.


There are 2 ways to create this cluster

  1. Imperative
  2. Declarative

Imperative configuration


Creating a deployment

k create deployment k8s-web-hello --image=dmaax/k8s-hello-from-express

Scaling up

k scale deployment k8s-web-hello --replicas=10

There are 3 ways to expose this deployment

  1. ClusterIP
  2. NodePort
  3. LoadBalancer

Exposing with ClusterIP

k expose deployment k8s-web-hello --port=80 --target-port=3000

Exposing with NodePort

k expose deployment k8s-web-hello --type=NodePort --port=3000

Exposing with LoadBalancer

k expose deployment k8s-web-hello --type=LoadBalancer --port=3000

Update a deployment with a newer docker image

k set image deployment k8s-web-hello k8s-hello-from-express=dmaax/k8s-hello-from-express:1.0.0

Monitor the update process

k rollout status deploy k8s-web-hello


Deleting a pod

k delete pod k8s-web-hello-6fb86f54fd-8ldcq

This pod is going to be recreated automatically, with another name.

Accessing k8s dashboard

minikube dashboard

This method may vary, this works if you're using minikube like me.


Declarative configuration


Create a deployment

k apply -f k8s/deployment.yaml

Scaling up/down

Modify the deployment file, under "spec" add or modify a field called "replicas" and set a number. After that, apply the changes:

k apply -f k8s/deployment.yaml

Create a service

k apply -f k8s/service.yaml

If you want to modify the type (ClusterIP, NodePort, LoadBalancer), under "spec" change the field "type". Afer that apply the changes:

k apply -f k8s/service.yaml

Delete a deployment/service

k delete -f k8s/deployment.yaml

If you want to delete the service use service.yaml.


Deleting deployment and service with one command

k delete -f k8s/deployment.yaml -f k8s/service.yaml