PODs in Kubernetes
Kubernetes does not deploy containers directly to the worker nodes. Containers are encapsulated in a Kubernetes object as known as pods. A pod is a single instance of an application, it is the smallest object that we can create in Kubernetes.
In the fact, mostly, a pod has 1 to 1 relationship with a container. its means when we want to scale up, we need to create a new pod with a container.
Sometimes we may have multiple containers in one pod, and it may do some supporting tasks for the main container such as processing uploaded files, and processing user data... two containers can communicate with each other via a local shared network. the 2nd container will live alongside the main container.
See Kubernetes overview: https://www.albertpham.me/2022/08/kubernetes-overview_0459759341.html
For more details
https://kubernetes.io/docs/concepts/workloads/pods/
Normally, When we want to deploy a container into the docker host we run the command:
docker run web-application
So with Kubernetes, we run:
kubectl run NAME --image=image
To see the list of pods in our cluster:
kubectl get pods
kubectl get pods -o wide
kubectl describe pod NAME
kubectl delete pod NAME
YAML file, What is that?
Key: Value
Fruit: Apple
Vehicle: car
OS: - Windows - MacOs - Linux
OS:
Name: Windows
Version: window 10
OS:
- Name: Windows
Version: window 10
- Name: MacOs
Version: Monterey 12.5.1
- Name: Linux
Version: Ubuntu 14.04
apiVersion: => (string) version of kubernetes version used to create object kind: => (string)type of object we want to create: POD, replica,... metadata: => (dictionary) data use to identify objects like, name, labels... spec: =>(dictionary) this is additional infomation for Kubernetes create object
kubectl create -f yaml-file.yal
kubectl apply -f yaml-file.yal
kubectl get pods
apiVersion: v1 kind: Pod metadata: name: nginx spec: selector: matchLabels: app: nginx replicas: 2 # tells deployment to run 2 pods matching the template template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
kubectl create -f create-pod.yaml
Để lại bình luận cho trang này