Pods
- Pod is an atomic unit of creation in k8s
- Think of Pod as a small package with one or more containers in it
- Every pod will get an unique ip in the k8s cluster
- Containers in the Pod have shared resources i.e.
- shared network
- shared storage
-
Consider typical application
-
If we have to run this in containers, we run each component in a container
-
When it comes it pods consider the following
- Each Pod can be scaled horizontally or vertically with other k8s workloads
- When pod has more that one containers, the primary container is referred as
maincarand all the other containers are referred assidecars
Interaction with k8s cluster
-
To interact with k8s we can use any client which can sent http(s) requests. k8s gives two simple options
- kubectl: A cli tool to interact with k8s api-server
- client libraries: Refer Here
- k8s api-server is by default https and the default configuration of k8s requires client to be authorized to communicate with k8s cluster.
-
Note: when we installed kubeadm, on the master node we have a file called as kube-config file
~/.kube/configwhich contains certificate data and api-server urls to connect
kubectl
- kubectl is a cli and it can be installed directly on any system
- Refer Here for installation
-
k8s allows to be interacted from kubectl in two ways
- with commands (imperative): we construct a command based on what we want
- with manifest files (declarative): we create a yaml file based on what we want and apply the file
- with commands (imperative): we construct a command based on what we want
- We would use declartive approach for regular activities.
Lets play with pods
- Today lets focus on imperative way of creating Pods
Create a pod with a name web1 with httpd container in it
- syntax
kubectl run <paramters> <name-of-pod>
- Example
kubectl run --image httpd web1
- To view the pods
kubectl get pods
- To view the pods with more info
kubectl get pods -o wide
- To delete the pod
kubectl delete pod <name>
- We can create pod and exec into contianer
Activity
- Create two pods
- web1 => nginx
- web2 => httpd
- execute the command
whoami - delete the pods
- note: use killercoda
Intro to Writing k8s manifests
- Manifest in k8s is where we express a desired state in the yaml form.
- k8s gives an api reference using which writing yaml files is easier Refer Here
- Watch video
