Docker and Kubernetes: Difference between revisions
Line 127: | Line 127: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
====Create an Image==== | ====Create an Image==== | ||
Easy pezzy lemon squeezy | Easy pezzy lemon squeezy. Where nigelpulton is your own Docker hub account/repository | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
cd getting-started-k8s/App | cd getting-started-k8s/App | ||
docker image build -t nigelpulton/getting-started-k8s:1.0 . | |||
</syntaxhighlight> | |||
====Store in repo==== | |||
Now push the image to your docker hub account. | |||
<syntaxhighlight lang="bash"> | |||
docker image push nigelpoulton/getting-started-k8s:1.0 | |||
</syntaxhighlight> | |||
====Define in a manifest==== | |||
We can define this in either Yaml or Json. | |||
<syntaxhighlight lang="yaml"> | |||
apiVersion: v1 | |||
kind: Pod | |||
metadata: | |||
name: static-web | |||
labels: | |||
role: myrole | |||
spec: | |||
containers: | |||
- name: web | |||
image: nginx | |||
ports: | |||
- name: web | |||
containerPort: 80 | |||
protocol: TCP | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 22:59, 13 August 2021
Introduction
Containers
This all started with VMWare where the total resource could be divided up to run more than one application on difference virtual machines. But VMWare required an OS on every machine and licenses in the case of Windows. They also needed managing, e.g. patching, Anti-virus and patching. Along came containers which shared the OS.
Docker
Docker Inc. Docker is a company which gave the word technology for containers. They are now a company which provides services around the company.
Docker is Open source and known as Community Edition (CE). The company Docker releases an Enterprise Edition (EE).
The general approach is to
- Create an image (docker build)
- Store it in a registry (docker image push)
- Start a container from it (docker container run)
The differences between EE and CE are shown below
Kubernetes
Kubernetes came out of Google and Open Source. Greek for helmsman or k8s (Kates). Kubernetes is an orchestrator and can schedule, scale and update containers. There are alternatives like Docker Swarm
Architecture
Overview
Apps are put in a container, wrapped in a pod and deployment details. They are provisioned on a Node inside a K8s Clustoer
Master
In general these are a hosted services on the cloud but you can run them locally on a linux box.
- This is the front-end to the control plane
- It exposes a RESTFul API consuming JSON and Yaml
- We send manifests describing our apps to this
The Cluster Store for users with large changes often separate this
The controllers controls
- Node Controller
- Deployment controller
- Endpoints/EndpointSlice
The scheduler
- Watches for new work
- Assigns Work to the cluster nodes
Kubernetes Nodes
Now its time for the Nodes. These are made up of three parts, the Kublet, Container runtime and the Kube Proxy
Kubelet
The Kubelet is the Main Kubernetes agent it
- Registers node with the cluster
- Watches API Server for work tasks (Pods)
- Executes Pods
- Reports to the master
Container Runtime
- Can be Docker
- Pluggable via Container Runtime Interface (CRI)
- Generally is Docker or containerd, other like gVisor and katacontainers exist
- Does the stop and starting of containers
Kube Proxy
- The Networking Component
- Does light-weight load balancing
Declarative Model/Desired State
We describe what we want the cluster to look like but we do not care how it happens. Kubernetes constantly checks the desired state matches the observed state.
Pods
A pod is a shared execution environment and can container one or more containers. It is the Pod which has a unique IP. Containers within the same pod must allocate unique ports if they are to talk to each other or the outside world. The same for volumes etc.When scaling you scale Pods not Containers.
Multi container Pods are for two different but complimentary containers which need to be aligned. An example of this might be a service mesh. For example the mesh container could be responsible for encryption or decryption. Note Deployment of Pods is atomic
Pods provide
- Annotations
- Labels
- Policies
- Resources
- Co-scheduling of contianers
and other Metadata.
Kubernetes Service Objects
As mentioned the IP address are provided for each Pod. However Pods die, we scales up and down and it would not be practical to use them so Kurbenetes provides the Service object which is describe in the deploymennt. With the use of labels the Service object knows which pods to send traffic to. By either removing labels from the pod the objects can be match generically.
In the example below both 1.3 and 1.4 will be matched of the Pods. Equally we could add a version to the service object and the unmatched version would not be used.
Service objects
- Only Send traffic to healthy Pods
- Can do session affinity (Sending of subsequent requests to the same Pod)
- Can send traffic to endpoints outside of the cluster
- Can do TCP and UDP
Kubernetes API Server
This is the API which exposes and RESTFul API. It exposes the various objects handles the requests. The objects are broken up into various sub categories. We use the command line kubectl to control this.
Installing Ubuntu
This was really easy. Had to use Firefox to get the dashboard to work on https://127.0.0.1:10443. Need to review how to get it to work on Chrome.
sudo snap install microk8s --classic
sudo usermod -a -G microk8s $USER
sudo chown -f -R $USER ~/.kube
su - $USER
microk8s status --wait-ready
microk8s enable dashboard dns ingress
microk8s kubectl get all --all-namespaces
microk8s dashboard-proxy
To be able to use the dashboard on chrome you need to go to chrome://flags/#allow-insecure-localhost and enable Allow invalid certificates for resources loaded from localhost. Firefox works by default.
Deployment
Introduction
We do this by
- Creating App Code
- Create an image
- Store in a repo
- Define in a manifest
- Post to the API Server
Example
Creating App Code
Clone the App Code
git clone https://github.com/nigelpoulton/getting-started-k8s.git
Create an Image
Easy pezzy lemon squeezy. Where nigelpulton is your own Docker hub account/repository
cd getting-started-k8s/App
docker image build -t nigelpulton/getting-started-k8s:1.0 .
Store in repo
Now push the image to your docker hub account.
docker image push nigelpoulton/getting-started-k8s:1.0
Define in a manifest
We can define this in either Yaml or Json.
apiVersion: v1
kind: Pod
metadata:
name: static-web
labels:
role: myrole
spec:
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
protocol: TCP