Software engineering notes

Docker Kubernetes

Features

Main components

More components explanation

Key difference between Replication Controller and Replica Sets: the replication controller only supports equality-based selector whereas the replica set supports set-based selector

Diagram for core components

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                           ┃
┃                          Kubernetes Cluster                               ┃
┃                                                                           ┃
┃   ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓                                        ┃
┃   ┃                              ┃                                        ┃
┃   ┃    Control Plane (Master)    ┃                                        ┃
┃   ┃                              ┃                                        ┃
┃   ┃   ┏━━━━━━━━┓ ┏━━━━━━━━━━━┓   ┃                                        ┃
┃   ┃   ┃  etcd  ┃ ┃ scheduler ┃   ┃                                        ┃
┃   ┃   ┗━━━━┳━━━┛ ┗━━━━━┳━━━━━┛   ┃                                        ┃
┃   ┃   ┏━━━━┻━━━━━━━━━━━┻━━━━━┓   ┃    ┏━━━━━━━━━┓                         ┃
┃   ┃   ┃                      ┣━━━╋━━━━┫ kubectl ┃                         ┃
┃   ┃   ┃      API Server      ┃   ┃    ┗━━━━━━━━━┛                         ┃
┃   ┃   ┃                      ┣━━━╋━━┓                                     ┃
┃   ┃   ┗━━━━━━━━━━━┳━━━━━━━━━━┛   ┃  ┃                                     ┃
┃   ┃   ┏━━━━━━━━━━━┻━━━━━━━━━━┓   ┃  ┃                                     ┃
┃   ┃   ┃  Controller Manager  ┃   ┃  ┃                                     ┃
┃   ┃   ┗━━━━━━━━━━━━━━━━━━━━━━┛   ┃  ┃                                     ┃
┃   ┃                              ┃  ┃                                     ┃
┃   ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛  ┃                                     ┃
┃                                     ┃                                     ┃
┃   ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓    ┃                                     ┃
┃   ┃                            ┃    ┃                                     ┃
┃   ┃    Node 1 (Worker)         ┃    ┃                                     ┃
┃   ┃                            ┃    ┃                                     ┃
┃   ┃   ┏━━━━━━━━━━━━━━━━━┓      ┃    ┃                                     ┃
┃   ┃   ┃     kubelet     ┣━━━━━━╋━━━━┛                                     ┃
┃   ┃   ┗━━━━━━━━┳━━━━━━━━┛      ┃                                          ┃
┃   ┃   ┏━━━━━━━━┻━━━━━━━━┓      ┃                                          ┃
┃   ┃   ┃    container    ┃      ┃                                          ┃
┃   ┃   ┃     runtime     ┃      ┃   ┏━━━━━━━━━━━━━━┓  ┏━━━━━━━━━━━━━━┓     ┃
┃   ┃   ┗━━━━━━━━━━━━━━━━━┛      ┃   ┃              ┃  ┃              ┃     ┃    ┏━━━━━━━━━━━┓
┃   ┃   ┏━━━━━━━━━━━━━━━━━┓      ┃   ┃    Service   ┃  ┃   Ingress    ┃     ┃    ┃    Load   ┃    ┏━━━━━━━━┓
┃   ┃   ┃    kube-proxy   ┣━━━━━━╋━━━┫  Cluster IP  ┣━━┫  Controller  ┣━━━━━╋━━━━┫  Balancer ┣━━━━┫ Client ┃
┃   ┃   ┃                 ┣━━┓   ┃   ┃  (1:N nodes) ┃  ┃              ┃     ┃    ┃           ┃    ┗━━━━━━━━┛
┃   ┃   ┗━━━━━━━━━━━━━━━━━┛  ┃   ┃   ┃              ┃  ┃              ┃     ┃    ┗━━━━━━━━━━━┛
┃   ┃                        ┃   ┃   ┗━━━━━━━━━━━━━━┛  ┗━━━━━━┳━━━━━━━┛     ┃
┃   ┃   ┏━━━━━━━━━━━━━━━━━┓  ┃   ┃                     ┏━━━━━━┻━━━━━━━┓     ┃
┃   ┃   ┃      Pod 1      ┃  ┃   ┃                     ┃   Ingress    ┃     ┃
┃   ┃   ┃ ┏━━━━━━━━━━━━━┓ ┣━━┫   ┃                     ┃ (route rules)┃     ┃
┃   ┃   ┃ ┃ container 1 ┃ ┃  ┃   ┃                     ┗━━━━━━━━━━━━━━┛     ┃
┃   ┃   ┃ ┗━━━━━━━━━━━━━┛ ┃  ┃   ┃                                          ┃
┃   ┃   ┃ ┏━━━━━━━━━━━━━┓ ┃  ┃   ┃                                          ┃
┃   ┃   ┃ ┃ container 2 ┃ ┃  ┃   ┃                                          ┃
┃   ┃   ┃ ┗━━━━━━━━━━━━━┛ ┃  ┃   ┃                                          ┃
┃   ┃   ┗━━━━━━━━━━━━━━━━━┛  ┃   ┃                                          ┃
┃   ┃   ┏━━━━━━━━━━━━━━━━━┓  ┃   ┃                                          ┃
┃   ┃   ┃      Pod 2      ┃  ┃   ┃                                          ┃
┃   ┃   ┃ ┏━━━━━━━━━━━━━┓ ┣━━┛   ┃                                          ┃
┃   ┃   ┃ ┃ container 1 ┃ ┃      ┃                                          ┃
┃   ┃   ┃ ┗━━━━━━━━━━━━━┛ ┃      ┃                                          ┃
┃   ┃   ┃ ┏━━━━━━━━━━━━━┓ ┃      ┃                                          ┃
┃   ┃   ┃ ┃ container 2 ┃ ┃      ┃                                          ┃
┃   ┃   ┃ ┗━━━━━━━━━━━━━┛ ┃      ┃                                          ┃
┃   ┃   ┗━━━━━━━━━━━━━━━━━┛      ┃                                          ┃
┃   ┃                            ┃                                          ┃
┃   ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛                                          ┃
┃                                                                           ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Basis

Advanced

(TODO)

Setup

(TODO)

Configuration

Each configuration file has 3 parts

fields

Example

apiVersion: apps/v1
kind: Deployment                    # a template for creating pods
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  replicas: 2                       # create 2 replica pods called my-app
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:                   # each pod replica has a container based on my-image
      - name: my-app
        image: my-image
        env:                        # environment variable
        - name: USER_NAME
          valueFrom:
            secretKeyRef:
              name: mongo-secret
              key: mongo-user
        ports:                      # ports configuration of this container
        - containerPort: 3000

ref: