Full Course for Beginners
By Amigoscode, Techworld with NaNa, and FreeCodeCamp
- How To Mount Volumes And Share Between Containers
- How to Build a Docker Image
- How to Containize Node API
- How to Reduce Size of Node API
- Always add versions to tags to prevent breaking changes.
Dockerfile
FROM nginx:1.21.0-alpine
Build with version tags
docker build -t website:1.21.0-alpine .
- A highly scabable server side application that stores and lets you distribute Docker images.
- Used in CI/CD pipelines.
- Runs applications.
- Can be private or public with Docker Hub, quay.io, and Amazon ECR.
Sign into Docker Hub
docker login
Format image names and tags, then push to Docker Hub
docker tag abechoi-website:latest abechoi/website:latest
docker tag abechoi-website:1 abechoi/website:1
docket tag abechoi-website:2 abechoi/website:2
docker push abechoi/website:latest
docker push abechoi/website:1
docker push abechoi/website:2
# pulls latest if tag is unspecified
docker pull abechoi/website
# returns low-level information on container
docker inspect user-service-api
# ctrl+f to search Cmd for commands
# returns logs
docker logs user-service-api
# returns logs in real-time.
docker logs -f abechoi-website
Orchestration provides high availability, scalability, and disaster recovery.
-
Master Node - UI, API, CLI a. API Server - Entrypoint to K8S cluster. b. Controller Manager - Keeps track of cluster events. c. Scheduler - Ensures Pods placement. d. etcd - Kubernetes backing key-value store and snapshots. e. Always have backup Master Nodes.
-
Virtual Network - Creates a unified machine of nodes.
-
Worker Nodes - Runs tasks assigned by the Master Node.
-
Pod a. Smallest unit of K8s. b. Abstration over container. c. Usually 1 application per Pod. d. IP address per Pod. e. New IP address on recreation.
-
Sevice a. Permanent IP address. b. Lifecycle of Pods and Services is not correlated. c. Load balancer.
-
Ingress a. Forwards IP address to Services.
-
ConfigMap a. External configuration of your application. a. Stores database URL.
-
Secret a. Used to store secret data, such as credentials in base64 encoded format.
-
Deployment a. Blueprint to replicate Pods. b. Defines replicas and scalability. c. Abstraction of Pods.
-
StatefulSet a. Replicates databases, but databases are often hosted outside K8s clusters.
K8s do not manage data persistance, so process the data to be stores locally or remotely.
-
Minikube a. A lightweight hybrid node of master and worker. b. A single node K8s cluster that runs in Virtual Box. c. For testing purposes.
-
Kubectl a. Command line tool for Kubernetes. b. Creates and destroys Pods. c. Creates services.
-
Commands
# start minikub with hyperkit as vm driver
minikube start --vm-driver=hyperkit
# returns information about the minikube
minikube status
# returns all | nodes | pods | services | deployments
kubectl get all | nodes | pods | services | deployments
# creates a pod using nginx image
kubectl create deployment nginx-depl --image=nginx
# returns logs
kubectl logs nginx-depl-5c8bf76b5b-qj9tc
# returns info about node | pod | service
kubectl describe node | pod | service NAME
# access interactive shell
kubectl exec -it mongo-depl-5fd6b7d4b4-wwwtz -- bin/bash
- How to Create and Apply a Config File
- How to Connect Mongo DB and Express Pods