Giter VIP home page Giter VIP logo

example-kubernetes-nodejs's Introduction

example-kubernetes-nodejs

Introduction to Kubernetes (k8s) with Node.js.

Requirements

  • Kubernetes (or minikube)
  • kubectl
  • Docker

Helpers

  • Re-using local Docker daemon with minikube: eval $(minikube docker-env) (run it once before Docker build)
  • On OSX: To base64: pbpaste | base64 | pbcopy and From base64: pbcopy | base64 --decode
  • minikube start and minikube stop

Tasks

1. Build Docker image

Re-using local Docker daemon with minikube:

eval $(minikube docker-env)

Building Docker image:

cd src/gateway
docker build -t my-co/gateway:v1 .

2. Create Secret, Deployment and Service in Kubernetes

kubectl create -f k8s
kubectl get deployment
kubectl get deployment <deployment-name> -o yaml
kubectl edit deployment <deployment-name>
kubectl get secret
kubectl get secret <secret-name> -o yaml
kubectl get service
kubectl get service <service-name> -o yaml

3. Get running pods

kubectl get pod
kubectl describe pod <pod-name>

Edit replica number in gateway Deployment and get pods again.
WARNING: Always edit yaml files in Kubernetes via kubectl, it's not synchronized with your local k8s folder.

4. Kill one pod

kubectl get pod
kubectl delete pod <pod-name>
kubectl get pod

5. Test networking

Go to inside a running pod:

kubectl get pod
kubectl exec <pod-name> -it -- sh
nslookup kubernetes gateway
curl <host>:3001
curl <ip>:3001
env | grep GATEWAY

From minikibe:

minikube service gateway

6. Set Horizontal Pod Autoscaler (HPA)

Do you have a running Heapster (collects metrics for autoscaler)?

kubectl get pod -n kube-system

If no, install it from here: https://github.com/kubernetes/heapster

kubectl autoscale deployment gateway --cpu-percent=50 --min=1 --max=10
kubectl get hpa
kubectl get hpa gateway -o yaml
ab -n 10000 -c 100 <IP>

HPA runs every 2 minutes by default.

7. Templating

Checkout Helm and anchor.

example-kubernetes-nodejs's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.