Study notes
Enable Kubernetes
Docker desktop UI -> Settings -> Check enable Kubernets.
Restart Docker (not mandatory)
CheckKubernetes
Create file pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- name: testpod
image: alpine:latest
command: ["ping", "8.8.8.8"]
Create a pod with a single container that will ping 8.8.8.8(aftre start)kubectl apply -f pod.yaml
# Check pod
kubectl get pods
ResultNAME READY STATUS RESTARTS AGE
demo 1/1 Running 0 4s
And check pod logs
kubectl logs demo
Result:PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=37 time=21.393 ms
64 bytes from 8.8.8.8: seq=1 ttl=37 time=15.320 ms
64 bytes from 8.8.8.8: seq=2 ttl=37 time=11.111 ms
Terminate test pod
kubectl delete -f pod.yaml
Enable Docker Swarm
Docker Desktop runs primarily on Docker Engine, which has everything you need to run a Swarm built in
Initialize Docker Swarm mode
docker swarm init
ResultSwarm initialized: current node (tjjggog...) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3e0hh0jd5t4yjg209f4g5qp.......0j5x9 nnn.nnn.nnn.nnn:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
Run a simple Docker service that uses an alpine-based filesystem, and isolates a ping to 8.8.8.8
docker service create --name demo alpine:latest ping 8.8.8.8
# Check
docker service ps demo
ResultID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
463j2s3y4b5o demo.1 alpine:latest docker-desktop Running Running 8 seconds ago
docker service logs demo
Resultdemo.1.463j2s3y4b5o@docker-desktop | PING 8.8.8.8 (8.8.8.8): 56 data bytes
demo.1.463j2s3y4b5o@docker-desktop | 64 bytes from 8.8.8.8: seq=0 ttl=37 time=13.005 ms
demo.1.463j2s3y4b5o@docker-desktop | 64 bytes from 8.8.8.8: seq=1 ttl=37 time=13.847 ms
demo.1.463j2s3y4b5o@docker-desktop | 64 bytes from 8.8.8.8: seq=2 ttl=37 time=41.296 ms
...
Terminate
docker service rm demo
Deploy to Kubernetes
In order to validate that our containerized application works well on Kubernetes, we’ll use Docker Desktop’s built in Kubernetes environment right on our development machine to deploy your application
When all is good the app will be handed off to run on a full Kubernetes cluster in production
The Kubernetes environment created by Docker Desktop is fully featured, meaning it has all the Kubernetes features your app will enjoy on a real cluster, accessible from the convenience of your development machine.
1. Describing apps using Kubernetes YAML
...to be a real world example - Deep learning experiment run locally.
Deploy to Swarm
Your application run as stand-alone containers, deployed using Kubernetes, Let’s look at how to arrange for them to be managed by Docker Swarm.
Swarm provides many tools for scaling, networking, securing and maintaining your containerized applications, above and beyond the abilities of containers themselves.
In order to validate that our containerized application works well on Swarm, we’ll use Docker Desktop’s built in Swarm environment right on our development machine to deploy our application, before handing it off to run on a full Swarm cluster in production.
Swarm workloads are scheduled as services, which are scalable groups of containers with added networking features maintained automatically by Swarm.
...
Important
In Swarm, a service provides both scheduling and networking facilities, creating containers and providing tools for routing traffic to them. In Kubernetes, scheduling and networking are handled separately: deployments (or other controllers) handle the scheduling of containers as pods, while services are responsible only for adding networking features to those pods.
...to be a real world example - Deep learning experiment run locally.
Resources:
Orchestration | Docker Documentation
Running Local Kubernetes Cluster in Docker Containers | ComputingForGeeks
Live Debugging Node.js with Docker (play-with-docker.com)