This note is based on: https://www.youtube.com/watch?v=X48VuDVv0do
[TOC]
-
A pod is a smallest unit of K8s.
-
It is an abstraction over container. K8s do this because they want you to only interact with the kubernetes layer and don't need you to know about containers
-
usually 1 application per pod
-
each pod gets its own IP address
-
new ip address on re-creation(pods are ephemeral)
- this is not ideal and inconvenient(reason for Service)
- Service is a static/permanent IP address that can be attached to each pod
- Service is also a load balancer
- There are external and internal services
- External services communicate with public world, i.e. hosting website
- Internal services, i.e. database
- The url for your service typically look like this: protocol://service_ip:application_port.
- You don't want users to access your web like this :).(reason for Ingress)
- Ingress bascially forward the request to the service
Now, consider this scenario:
You store your database url in your application code, i.e. mongo_database. Later, the url is changed. This means you'll need to modify your source code in the docker image and redeploy the pod. NOT GOOD.(reason for ConfigMap)
- External configuration of your application
- For example, put database_url in the config
- Connect the ConfigMap to the pod, then pod can get those config data
- Feels like a seperate tiny database for your application
- You don't store secret data in Config Map.(reason for Secret)
- Secret is basically an encoded ConfigMap
- Both local and remote storage can be attached to a pod
Of course you want replicas
- Deployment is a blueprint for your application(pod), you specify how many replicas you need.
- In practice, you don't create pods, you create deployments
- Abstraction of Pods
- However, Deployment cannot replicate database because it has a state, which is its data. Mechanisms needed to avoid data inconsistency(reason for StatefulSet)
- Handle syncronization
- Each replica has unique identity and their own storage, which store their states.
- A replica is not created until the previous replica is created. Deletion happens in reverse order.
- StatefulSet in k8s is complex. Therefore, people usually deploy their database application outside k8s, and only deploy stateless application on k8s
- A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the cluster, Pods are added to them. As nodes are removed from the cluster, those Pods are garbage collected. Deleting a DaemonSet will clean up the Pods it created.
- Each Node has multiple Pods on it
- There are 3 processes that must be installed on every Node. These 3 processes schedule and mange the pods
- container runtime, i.e. docker
- kubelet
- Kubelet interacts with both the container and the node itself
- Kubelet starts the pod with a container inside. Assigning resrouces from the nodes to pods
- Kube Proxy
- KP forwards the requests to the approriate pod through Service
-
There are 4 processes that runs on every master node
-
Api server
-
Cluster gateway(A single entry point)
-
Gatekeeper for authentication
-
This is what your kubectl cmds is interacting with
-
-
Scheduler
- Schedule pods on worker nodes
- Scheduler just schedule where the pod should be. Kubelet is the one that really starts the pod
-
Controller manager
- Detects cluster state changes, i.e. pods die
- After detection, ask scheduler to replace the pod for example
-
etcd
- A Key Value store of all the cluster changes
- It's the cluster brain
- Of course, the application data is not stored in etcd
-
- kubectl create deployment
- kubectl edit deployment
- This will open up a config file of the certain deployment to enable editing
- kubectl delete deployment
- This will remove all the pods created by this deployment, including all replicas
- kubectl apply -f
- It can create or update the component
- kubectl logs
- Kubectl get pod -o wide
- Provides little bit more info about the pod
- kubectl describe pod
- Shows the detailed status of a pod
- Kubectl exec -it -- bin/bash
- Get interactive terminal of the pod
Each config file has 3 parts
- metadata
- specification
- Attributes of spec are specific to the kind, i.e. Deployment or Service
- status
- Auto generated by k8s
- This comes from etcd of the master node :)
We use label under metadata to label the resource with any key-value pair. Then we use selector under spec to connect to a label
![image-20210611110906689](/Users/weisy/Library/Application Support/typora-user-images/image-20210611110906689.png)
We need to match ports too
![image-20210611111207128](/Users/weisy/Library/Application Support/typora-user-images/image-20210611111207128.png)
- Virtual cluster in the cluster
- Group resources
- Separate teams
- Resource sharing and reuse
- Access and resource control
-
You can't access most resources from another namespace
- For example, ConfigMap and Secret cannot be shared across namespaces
- Services are accessable between namespaces
-
Volumn and Node are not Namespace specific
- Package manger for k8s(yum for linux)
- Can also be a template to generate k8s yaml config in batch
- Bundle of YAML files
- Just a package for package manager :)
-
You want a storage that doesn't depend on the pod lifecycle
-
Storage must be available on all nodes
-
Storage needs to persist even cluster crashed
- A component of k8s, link to hardware backend
- Outside of namespace. Accessible to the whole cluster
- Claim a usage of the PV
- The pod then use this claim to get access to the storage
- The pod decide which container can mount the volume
- ![image-20210611145857698](/Users/weisy/Library/Application Support/typora-user-images/image-20210611145857698.png)
- ![image-20210611145948554](/Users/weisy/Library/Application Support/typora-user-images/image-20210611145948554.png)
- SC provisions PV dynamically when PVC claims it