- First step 01 - Docker Crash Course for Absolute Beginners. ✅
- Second step 02 - Learn Docker Compose - From Zero to Hero in 1 Hour.
- Good to Know - Prerequisite step - Yaml Tutorial | Learn YAML in 18 mins. ✅
- Good to Know - Prerequisite step - Microservices explained - the What, Why and How?
- Third step 03 - Kubernetes Crash Course for Absolute Beginners. ✅
Tasks and notes from crash course. Made by TechWorld with Nana. Contains my own notes for not just watch videos.
If the content sparked 🔥 your interest, please consider staring the course and start learning 📖.
Note: The material provided in this repository is only for helping those who may get stuck at any point of time in the course. It is very advised that no one should just copy the solutions(violation of Honor Code) presented here.
-
Make combined certificate for all these software development tools.
-
If time and patience take full course: Docker Tutorial for Beginners FULL COURSE in 3 Hours.
- Section 01 - Intro and Course Overview. ✅
- Section 02 - What is Docker? ✅
- Section 03 - What problems Docker solves in development and deployment process. ✅
- Section 04 - Virtual Machine vs Docker. ✅
- Section 05 - Install Docker. ✅
- Section 06 - Docker Images vs Containers.
- Section 07 - Docker Registries.
- Section 08 - Docker Image Versions.
- Section 09 - Main Docker Commands - Pull and Run Docker containers.
- Section 10 - Port Binding.
- Section 11 - Start and Stop containers.
- Section 12 - Private Docker Registries.
- Section 13 - Registry vs Repository.
- Section 14 - Dockerfile - Dockerize Node.js app.
- Section 15 - Build Image.
- Section 16 - Docker UI Client.
- Section 17 - Overview: Docker in complete software development lifecycle
- Section 18 - Where to go from here.
- We will be covering following:
- Container is packed all the different parts inside.
- Before Docker, all developers needed to install their own setups of tools for their specific needs.
- Os specific.
- Configuration specific.
- Etc.
- Setting up environment individually different to different OS.
- All these dependencies are inside container.
- As developer, you just need to execute one docker command and get docker container package
docker run postgres.
- Docker standardizes process of running any service on any local dev environment.
- More time for development than setting up configuration.
- With Docker, you can have same service running on local device whiteout any conflict.
- With containers → DevOps team just needs to fetch and run Docker artifact.
- Different versions of same application. This is very difficult without docker.
- Old way was, develop and ship it to the DevOps team, which made configuration and installation. This was very error-prone.
- There will be Docker Artifact which handles.
- Big questions below.
-
OS will be installing on the system, and it will communicate between different layers.
-
Software will be on top of application layer. This will be communicating with the OS layer.
- So the big question these both docker and vm are virtualization tools, so which layer these both virtualize.
- Docker virtualize OS Application Layer.
- Virtual machine virtualizes. OS Application Layer and OS kernel → Meaning virtualizes complete operating system.
- What it means:
- Docker image is, a couple of MB.
- Dockers container takes seconds to start.
- Dockers compatible only with Linux distros.
- Vm images, a couple of GB.
- Vm takes minutes to start.
- Vm is running with all OS.
- Docker can't run Linux based docker image in Windows Host.
- Docker Desktop.
- Linux containers run on Windows or macOS.
- This is solved with Hypervisor layer with small Linux distro.
install Docker Desktop.
- Installing latest from docker website.
- This image is like .zip and .jar file.
-
Docker images are like .jar a file packaged in containers.
- It has compiled code.
- It also has complete environment configuration.
- Application, any services(Js app)(node, npm) needed, Os Layer(Linux).
- Add env variables, create directories.
-
Docker Container is running image.
-
You can one you can run multiple container.
- Images can be run in containers
-
docker imagesShow what images we have locally -
docker psList running containers
-
There are images stored in Docker Register
-
Official images are available from applications like Redis, Mongo, Postgres etc.
- There can be verified "Official" images or unofficial ones.
-
One the biggest docker register store is DockerHub
- One of Reddis Images
- If you need specific version, you can choose specific docker image which has right tag
latestis the latest which was build
- To download image
docker pull nginx:1.23
-
To list images
docker images -
Running images into container
docker run nginx:1.23- With
-dstop blocking
- With
-
Docker generates random name automatically
- We need to expose container ports
- This is done with Port Binding
- You can see what ports containers are running in
- Port inside container
- Exposing port to local host
- We can expose ports to localhost when creating container with special flag
- We can publish ports when creating image with flag
docker run -d -p 9000:80 nginx:1.23
- With following port structure
- After running with opening with following ports
- We can see what is being mapped on
- Now we can see its deployed into port 9000
-
To expose logs from docker
docker logs 6cb988ce6e05, where last one is docker id
-
It's standard to bind same port into container and which is exposed outside of container
-
Docker run always creates new container
-
To see all container which docker have created. You can use
docker ps -a
- To start container you can use
docker start {container} = start one or more stopped containers. Exampledocker logs 6cb988ce6e05
- When companies, creates their own public private docker registries.
- We want to build our docker image, when our application version is finished
- We do this by writing "definition" how to build image
- This is called docker file
- We do this by writing "definition" how to build image
- Telling to build base image FROM base image
-
In docker file you can run Linux commands!
- This is done with RUN directive
-
COPY copies files from src and adds them to containers path
-
WORKDIR /app changes working directly inside docker
-
Last command in docker file is CMD
FROM node:19-alpine
COPY package.json /app/
COPY src /app/
# COPY src /app/, last / is important. Docker will create new folder if there is no
WORKDIR /app
RUN npm install
CMD ["node", "server.js"]
- Building image
docker build -t node-app:1.0 .- Last one is location of Dockerfile
-
You can see image is created in layers
-
We can run our newly created image
docker run -d -p 3000:3000 node-app:1.0 -
We can see that our application inside docker is running and its being exposed to
localhost:3000
- Same tool is found in UI.
- CI server can create docker image automatically
- After commit, CI server can be configured with to push and create docker image into Private Repository
- We can connect docker app and MySQL with help of network
- When running docker container they are running in isolated networks
-
Listing all network
docker network ls. -
Creating docker network
docker network create spring-net. -
Connecting our container with given network
docker network connect spring-net mysqldb. -
Inspecting our container for attached networks
docker container inspect mysqldb. -
We can attach container to certain network when starting the container.
docker run -p 9090:8080 --name app --net spring-net -e MYSQL_HOST=mysqldb -e MYSQL_USER=root -e MYSQL_PASSWORD=root -e MYSQL_PORT=3306 app
-
Starting and pulling and starting MySQL image
docker run -d -p 3307:3306 --name mysqldb -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=user_rest_demo mysql. -
To test connection
localhost:3007and configureallowPublicKeyRetrievalto true.
- When restarting application data is lost, we can use volumes to keep data saved.
Tasks and notes from crash course. Made by TechWorld with Nana.
If the content sparked 🔥 your interest, please consider staring the course and start learning 📖
Note: The material provided in this repository is only for helping those who may get stuck at any point of time in the course. It is very advised that no one should just copy the solutions(violation of Honor Code) presented here.
- Section 01 - Intro and Course Overview
- Section 02 - Pre-Requisites to learn Docker Compose
- Section 03 - What is Docker Compose
- Section 04 - Demo - Without Docker Compose
- Section 05 - Why Docker Compose
- Section 06 - From Docker Commands To Compose File
- Section 07 - Create Compose File and start application
- Section 08 - Control Startup Order
- Section 09 - Docker Compose Commands (Up and Down vs Start and Stop)
- Section 10 - Connect own web application
- Section 11 - Variables in Docker Compose
- Section 12 - Docker Compose Secrets
- Section 13 - Use image from private repository
- Section 14 - Limitations, Docker Compose vs Kubernetes
- We will cover:
- What is Docker compose
- What problems it solves?
- Common Use cases
- Hands-on demos
- Limitations of Docker compose
- It's necessarily to know Docker containers before this one, if no Watch
- It's advised to learn YAML format, if no Check
- Application can be broken into smaller pieces.
- Or Microservice application.
- All of these software components must be containerized and deployed/run together.
- These services need to communicate together.
- We need some tool to control these actions:
- Define and run multiple Services in 1 environment.
- Each container is having own configuration and for this we can use Docker Compose, which makes our life easier.
- Demo will have 2 Docker containers.
- Just with Docker commands.
- Create Docker Network.
- Start MongoDB Container.
- Start Mongo Express Container(UI for MongoDB).
//Create mongo-network first
docker network create
mongo-network
- We can see network is being created.
//List all networks
docker network ls
-
Running MongoDB in Docker.
- You can see default ports from Docker Hub and default usernames and passwords.
-
For mongoDB.
docker run -d -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=supersecret --network mongo-network --name mongodb mongo
- For mongo-express.
- Its just font-end for mongoDB.
docker run -d -p 8081:8081 -e ME_CONFIG_MONGODB_ADMINUSERNAME=admin -e ME_CONFIG_MONGODB_ADMINPASSWORD=supersecret -e ME_CONFIG_MONGODB_SERVER=mongodb --network mongo-network --name mongo-express mongo-express
- To try if these work go to
http://localhost:8081/and log in- MongoDB depends on mongo-express and to communicate each other isolated virtual network must be configured and working!
- Problem comes when a lot of containers are needed to start and configure to communicate
- We have one way to manage these → Docker Compose.
- This is based on YAML File
- Docker-Compose abstract all the CMD commands into docker-compose file.
- Required attributes for docker file!
- First line, version of docker-compose which needs to be compatible with Compose is installed locally
- Services. List all services, you want to run
- YAML transfers this cmd commands to .YAML one configurable file
- Here you can see one service being configured.
- Name of service being configured.
-
Container name, this will map form command to
-
From which image name docker container will be built from. You can specify version list
-
List of ports which will be mapping to container.
- Most time this
you have only one mapping
3.1Host port and3.2port inside Container
- Most time this
you have only one mapping
-
List of Environment variables for docker
- As you can see another service is below other one!
-
This how the YAML will look like for previous example configuration.
-
*Docker Compose can help your team to collaborate more efficiently since, now they can see how these services can be run separately. Not just random cmd commands.
- You don't have to include network to YAML configuration. This will be taken care by default in docker compose
- Docker takes care of creating docker network
- From services from list
- Docker takes care of creating docker network
- When making YAML file be careful of indentation
- Running YAML
- We are trying to execute compose file
- First we remove our old networks and containers
docker rm hashGoesHere // Removing container
docker network rm mongo-network // Removing docker network
-
If you have docker installed in your computer, you don't need to install Docker Compose
-
starting with docker compose
docker-build -f mongo-services.yaml upupargument for running from up to down different services
- You can see how network names are created. 1. prefix from folder where .YAML was run.
Docker basically takes folder where it was executed and prefixes with names.
- Docker logs are mixed since two containers were started at sane time.
-
When multiple services.
- When we need db before front-end
-
This decency can be done using
depends_on- This affects control of the services
- This will start container only when dependencies are finished
- Example using
depends_on:in case of mongo-express:
mongo-express:
image: mongo-express
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME=: admin
ME_CONFIG_MONGODB_ADMINPASSWORD=: supersecret
ME_CONFIG_MONGODB_SERVER=: mongodb
depends_on:
- "mongodb" # Takes list of services
-
Whole
mongo-expressservice won't be started, beforemongodbis up and running -
Running following Compose in detach mode
docker-compose -f mongo-services.yaml up -d
- We could stop containers using
docker stop, but with big compose files this get problematic
- We can close all containers in the same time and remove them with following command
docker-compose -f mongo-services.yaml down- This will clean networks, containers and docker images
- Data will be gone once container is removed
- Unless you define volumes
- Data will be lost when container is removed.
- Data will be saved.
- These have different use cases.
- Here we will add own app to our services
- todo
- todo
- todo
- todo
Tasks and notes from crash course. Made by TechWorld with Nana.
If the content sparked 🔥 your interest, please consider staring the course and start learning 📖.
- If time and patience take full course: Kubernetes Tutorial for Beginners FULL COURSE in 4 Hours
- Section 01 - Intro and Course Overview. ✅
- Section 02 - What is Kubernetes. ✅
- Section 03 - Kubernetes Architecture. ✅
- Section 04 - Node and Pod. ✅
- Section 05 - Main K8s Components. ✅
- Section 06 - Node & Pod. ✅
- Section 07 - Service & Ingress. ✅
- Section 08 - ConfigMap & Secret. ✅
- Section 09 - Volume. ✅
- Section 10 - Deployment & StatefulSet. ✅
- Section 11 - Kubernetes Configuration. ✅
- Section 12 - Minikube and Kubectl - Setup K8s cluster locally. ✅
- Section 13 - Complete Demo Project: Deploy WebApp with MongoDB. ✅
- Section 14 - Interacting with Kubernetes Cluster. ✅
- Section 15 - Congrats! You made it to the end. ✅
- Introduction.
- Main components
- Setup.
- Demo project.
- There can be hundreds or thousands of containers.
- What problems does Kubernetes solve?
- What are the tasks of the orchestration tool?
- What features orchestration tool offer?
- User can access is it fast!
- More load when more load.
- Backing up data, if something goes wrong.
- At least one master node.
- Worker Node referred as
Nodes- These having
kubeletprocess running on it.- This is part of Kubernetes, so these nodes can communicate with each other.
- These having
- Each work node has docker containers deployed on it!
- So what is running on master node? There is multiple kubernetes processes running here to manage the cluster.
- API Server, gateway to the K8 cluster.
- 1.2 This gateway can be accessed thought UI, API or CLI.
- Keep overview what happening in cluster.
- Scheduling work and loads on node.
- etcd has status data of nodes and configurations. Back up process is made form these etcd configurations.
- Nodes are talking together with help of this Virtual Network.
- Network turns nodes into one this big powerful machine.
- Most load will be on Worker Nodes, so these are most of time bigger.
- Master Node is much more important, once you lose Master Node, you will lose access to the kubernetes cluster.
- So you will have multiple masters for backup.
- Main components of Kubernetes.
- Node is virtual or physical machine.
- Pod is smallest unit of Kubernetes.
- Pod is abstraction over container.
- Pod is usually ment to run one container at the time.
- It is possible to run multiple container inside one pod.
- Kubernetes has its own network, each pot get own IP address. Internal IP address.
- Pods are ephemeral!
- pods can die easily.
- Pod will die to some here, and new one will get its place.
-
This new pod is having new IP address.
- So, every time IP address are need to configure again!
-
This is where concept Service comes in!
- Service can attach to pod, it will have own IP address.
- If pod dies, IP address of pod will stay! No need to change endpoint.
- App should be accessible from external sources. We we need open External Service.
- db should not be accessible from outside. Internal Service.
- Ingress, will provide HTTPS and URL name for External Service.
- If the endpoint or service name will change, all of these needs to be ran.
- Kubernetes has ConfigMap, it will save all the URL data.
- You just point to this ConfigMap for URL.
- Saving all the non-confidential data in ConfigMap is risky, that why there is Secret.
- Passwords and user names can be also configured.
- There is service called Secret which saves passwords and user in safe way. Kubernetes does not save these in save format. Kubernetes advices to use 3rd party tools to encrypt the passwords.
- We just need to connect this one to the pod.
- PRO TIP. We can use secret references in properties file or in env variable.
- This Secret can have passwords, certificates and other things which needs to be encrypted.
- Whiteout Volumes data would be lost from db when restarted.
- Attaches hard drive to your pod or remote storage.
- Now when database pod is restarted, all the data is persisted.
- Its admins job to handle kubernetes data into right place.
- We are replicating on pod in multiple servers.
- In case if pod dies.
- Node being replicated and connected trough service.
- Service having, permanent IP and load balancer.
- For replicating pod we would.
- Define blueprint for Pods and use this blueprint for creating much of replicas as needed.
- This is called deploy in Kubernetes components.
- You will not be creating pods, you will be creating deployments.
- In deployments you can scale down or up.
- When pod dies, other one will take its place.
- We can't replicate via Deployment!
- We need to control who access data inside db.
- Mechanics needed which pod is reading or writing to the specific database .
- statefulset kubernetes components.
- StatefulSet should be used when want to use of stateful features.
-
StatefulSet in usage of kubernetes cluster can be difficult.
-
DB are often hosted outside of Kubernetes cluster.
- These core components, we can build kubernetes clusters.
-
All nodes which Kubernetes has goes trough API SERVER.
- All of these requests can be made trough UI, API and CLI.
-
Configuration for creating component called
deployment.
- Kubernetes configuration has three parts.
- First part is metadata of component.
- Second part is specifications. We put here configuration what we wan't to apply to that component.
-
spec are specific to the kind of configuration.
-
The Third part is a status.
- Status is automatically generated and added by Kubernetes.
- When Kubernetes notices difference between Desired and Actual state. Kubernetes tries to fix this using its self-recovery features.
- Example here, we want two replicas of
nginxdeployment.
- Example here, we want two replicas of
- Kubernetes will add here status of deployment and updates it constantly.
-
If only one replica is detected to be running by comparing the specification.
-
Another replica needs to be created ASAP .
- Where does K8 gets this status data?
- ETCD holds any data of k8 component! So, it also holds status data.
- These configurations files are usually stored with you code.
- Or own git repository.
- In production there is usually multiple Masters.
- There is also multiple Worker Nodes.
- These have all have separate responsibilities. Master and Node. So there will be separate virtual or physical machines, which each represent node.
- Setting up cluster like this will be difficult, since it needs lot of resources.
- CPU, Memory etc...
-
Minikube tool which has one node cluster. Which has master processes and Worker processes running inside one machine.
-
It has docker pre-installed.
- Kubectl is tool to interact with cluster.
- Create pods or other k8 components.
- Api Server is main entry point to the K8 cluster.
- To talk to Api Server is trough different client. KUBECTL is most powerful of three clients.
- Once kubectl submits command to the server. Worker processes will make things happen.
- Create pods ... etc.
- Kubectl can be used to interact with Minikube cluster or with Cloud cluster.
- This can be interacted with any type of cluster type.
- There are multiple ways to launch minikube.
- One is Container.
- Other is Virtual Machine.
- Instructions for starting. Minikube start.
-
If minikube will be ran as Container.
- You need driver installed as following, example. Docker.
-
If minikube will be ran as Virtual Machine.
- You need driver installed as following, example. VirtualBox.
- Docker is recommended driver to be used with any situation.
- minikube comes with docker runtime and also driver for minikube where its hosted itself.
- There will be layers of docker.
-
Starting minikube with driver.
minikube start --driver docker. -
Asking status.
minikube status. -
kubectlget installed as dependency when install minikube.
- We can get status of the nodes in the cluster.
kubectl get node.
- In cluster, we will have Webapp and Mongodb.
- Which will get configurations form Secret and ConfigMap.
- We will crate 4 K8 configurations.
- For ConfigMap.
- For Secret.
- Configurations for MongoDB.
- Configuration for WebApp.
- We can use kubernetes documentation. Example for config map format.
- Example of ConfigMap.
- Example of ConfigMap.
apiVersion: v1
kind: ConfigMap
metadata:
name: mongo-config
data:
mongo-url: mongo-service # This will be Service name of the MongoDB. This will be endpoint of MongoDB.
-
You can encode text using git bash
echo -n mongopassword | base64.- These can be used for kubernetes secret.
-
Example of Secret.
apiVersion: v1
kind: Secret
metadata:
name: mongo-secret
type: Opaque
data:
mongo-user: bW9uZ291c2Vy
mongo-password: bW9uZ29wYXNzd29yZA==
- We can reference these from different deployments.
templateis Configuration for the Pod.containersyou can have multiple containers within the pod.- These are usually images form docker hub.
- We will be using latest at the time
5.0or8.0Latest to the docker hub.
- In K8 you can label any component with the label.
- Adds additional label for identification.
- When you have multiple replicas from same pod. Every Pod has unique name.
- These can share common label.
- You can tell that these are shared form same pod.
- Important. Every pod needs label!!
-
We use Selectors for identifying pod replicas for specific deployment.
-
Pods with
nginxlabel which matches to the deployments labelnginx, are grouped together. -
Standard for naming labels is using
appfor given label.- Example.
app: nginx.
- Example.
-
replicas: 1how many replicas we want from this deployment.- For database, we don't want to use deployment, we want stateful set.
- Service needs to forwards the request to specific pod.
- Port of where the request is coming into.
- Port of the service.
- Which port request is forwarded into, port of the pod.
targetPortshould becontainerPort.- Which port request is forwarded into in the pods
- Example of Deployment configuration.
# Deployment & Service in one file.
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo-deployment
labels: # label for deployment is optional, but recommended.
app: mongo
spec:
replicas: 1 # how many pods using this blueprint.
selector:
matchLabels:
app: mongo # Standard is using app, and the label name.
template:
metadata:
labels: # For pods this is required.
app: mongo
spec:
containers:
- name: mongodb
image: mongo:8.0 # We are using 5.0 image version.
ports:
- containerPort: 27017
- Example of Service configuration.
# Service Configuration.
apiVersion: v1
kind: Service
metadata:
name: mongo-service # This is name of the service, which is used to access mongo.
spec:
selector: # Points to the Pod where this service belongs to.
app: mongo # The label of the pod.
ports:
- protocol: TCP
port: 9376 # Port of service. Standard these should be same.
targetPort: 9376 # Port where to forward into. Standard these should be same.
- We need to pass Secret and CofigMap the pods.
- We are referring Secret like such.
- We refer to ConfigMap with similiar way.
- name: DB_URL
valueFrom:
configMapKeyRef:
name: mongo-config
key: mongo-url
- We can use NodePort for making app accessible from external call.
- NodePorts are the port which will be opened to the K8 Nodes.
-
We have minicube cluster running, but there is now component running.
-
Getting pod
kubectl get pod- Before this one need ConfigMap and Secret must be existing before Deployments.
-
We need components before referencing those components.
- Deploying to the k8 with
applytakes k8 file as input.- Following commands:
kubectl apply -f mongo-config.yaml
kubectl apply -f mongo-secret.yaml
kubectl apply -f mongo.yaml
kubectl apply -f webapp.yaml
- My
webapp.yamland docker hub image DockerHub Image.
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
labels:
app: webapp
spec:
replicas: 1
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: nanajanashia/k8s-demo-app:v1.0
ports:
- containerPort: 3000
env:
- name: USER_NAME
valueFrom:
secretKeyRef:
name: mongo-secret
key: mongo-user
- name: USER_PWD
valueFrom:
secretKeyRef:
name: mongo-secret
key: mongo-password
- name: DB_URL
valueFrom:
configMapKeyRef:
name: mongo-config
key: mongo-url
---
apiVersion: v1
kind: Service
metadata:
name: webapp-service
spec:
type: NodePort
selector:
app: webapp
ports:
- protocol: TCP
port: 3000
targetPort: 3000
nodePort: 30100
- We only need to refer one Secret from many Deployments.
- All the components created form the cluster.
kubectl get all- Example below.
- For ConfigMap and Secret we need to use different commands.
kubectl get configmap.kubectl get secret.
- Example of using this commands for service
kubectl describe service webapp-service.
- We can check logs from specific pod.
-
Delete
kubectl delete deployments --all. -
To get help.
kubectl --help. -
Which IP address we can access this service?
- We can access this from cluster IP address.
- We can use
minikube ip.
- We can use
- Finish.















