Kubernetes for nodeJS dev

Course notes from Dan Wahlin’s excellent pluralsight course titled: Kubernetes from Developers: Core Concepts

Introduction

A way to manage containers.
Alternative to docker-swarm.
Locally, using docker compose is fine, but not ideal for production. For production we can scale, self-heal, update containers better, better networking capabilities, etc…
Works by having one master node which manages a number of other nodes.

Running locally

Run via docker desktop. Turn on kubernetes in dashboard. In terminal run commands to master node via the kubectl command.

Web UI dashboard

UI view of kubernetes clusters.

https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/

Nodes

A node is a collection of pods. The master node communicates with a cluster of nodes, each node contains a pod, each pod contains a container, (usually). Has agent to communicate with master called, kubelet. Has container runtime. Has networking via, kube-proxy.

Master node

Contains a number of services:

  • Store, which is like a DB of nodes in the cluster.
  • Controller manager, managing requests.
  • Scheduler, when updates will occur.
  • API server, $kudectl, to communicate with node.

Pods

A pod is a packaging for a container. You can have many pods on a given node. Usually one pod will contain one container. They can easily be removed and new ones created, (old ones can not be bought back). They have unique IP address. Containers within pods have unique ports. They never expand nodes.

Used internally to find out the health of a container. User can create their own probes.

  • Liveness probe, determines health of pod, (e.g. hit health check endpoint).
  • Readiness probe, when it’s ready for requests to start being made.

Deployments / ReplicaSets

ReplicaSets document how we want the pods managed.
Deployment wraps replicaSets, uses replicaSets to manage pods. Used to scale pods. Uses a pod template instead of creating a pod yaml directly.

Rolling, blue-green, canary, rollbacks.

Rolling example. Two existing and two new pods. Adds first new pod, removes first old pod, adds second new pod, removed second old pod.
This happens by default when we run kubectl apply.

Services

Entry point for accessing pods. Labels are used to associate pods with services. Pod, and their IPs, are ephemeral, unlike services, so services are used to abstract this. They do pod load balancing.

  1. ClusterIP, default, talks via internal IPs within cluster.
  2. NodePort, has IP on node and sets up static port.
  3. LoadBalancer, external IP as LB for nodes.
  4. ExternalName, service to DNS.

Storage

Volumes are a way of storing data which can be accessed between pods. Similar to how volumes are mounted for containers, but with greater options.

  1. emptyDir, stored only during life of pod.
  2. hostPath, mounts to nodes filesystem.
  3. nfs, mounted to network file system volume on network.
  4. configMap/secret, key value pairs for secrets.
  5. persistentVolumeClaim, persistent storage, e.g. NFS, cloud.
  6. cloud, global storage.
  7. plus more…

PV, is the persistent volume.

PVC, pv claim, link between the pod and the PV.

A way of templating persistent volumes as they can be dynamically created rather than having to contact admin.

ConfigMaps

Way to store config info and provide it to containers, (e.g. env var/secrets). Can be set via ConfigMap manifest, key value pair file using kubectl to upload to kubernetes from-file or from-env-file , individual data values from-literal .

Can be created on an individual bases via kubectl, from a file or separate command for TLS certs.

YAML examples

Course

All information taken from Dan Wahlin’s excellent pluralsight course titled: Kubernetes from Developers: Core Concepts

Software dev — Javascript, node, express, mongo, react, redux, rxjs, es6, ramda

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store