Entities which Kubernetes keeps to maintain states are Kubernetes objects. Like Deployments, SatefulSet, DaemonSet etc.
These objects are responsible to define the current situation of the cluster as well as the desired situation.
For example, suppose you wanted to run 2 replicas of a pod but only 1 is running, then Kubernetes will know about it and try to run the 2nd replica.
What Kubernetes Objects Represents?
Basically they represents the state of the cluster. Like –
- Information about the running containerized applications.
- Resource utilization like CPU, Memory, Storage etc.
- Policies attached to those containers like restart, upgrades etc.
Main Components of Kubernetes Objects
There are 2 main components –
spec
status
spec defines the properties. Like in deployment file we set spec for number of replicas. This commands Kubernetes to maintain the given number of replicas for the pod.
status represents the current state of cluster. Like the resource utilization by a pod.
Kubernetes keeps these two components in sync and if they behave differently then K8s takes the necessary action.
For example, if spec defines 2 replicas and status shows that only 1 is running then it means both spec and status are out of sync. Kubernetes will immediately run a new replica to match the spec.
Types of Kubernetes Objects
There are many types of Kubernetes objects. Some of them are listed below –
- Deployments
- StatefulSets
- ReplicaSet
- DaemonSet
- Jobs
- CronJob
How to create a Kubernetes object?
We create Kubernetes objects using yaml
or json
files. An example of Deployment yaml file is shown below –
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
The most important parameters are –
- apiVersion
- kind
- metadata
- spec
Different types of objects will have different values for these fields. kind
represents the type of object. For Deployments, the value of kind
is Deployment
.
Conclusion
Kubernetes objects are the persistent entities which represents the state of the cluster. spec
and status
are the two main components which defines the working conditions of a cluster.
Kubernetes uses these objects to keep the system running according to the protocols defined by the user.
Kubernetes Series
- Introduction to Kubernetes
- Introduction to Docker, Containers, Images & Repository
- Install and Run Docker Images
- Docker Image – FROM, RUN, COPY, ENTRYPOINT, CMD, EXPOSE explained
- Why docker run or start command not running my container?
- How to list all docker images in system?
- How to list all docker containers?
- How to start/stop a docker container?
- Difference between docker run and docker start
- How to bind docker container port with host?
- How to get logs of docker container?
- How to live stream logs of docker container?
- Set custom name to a docker container
- Access docker container filesystem & terminal
- Getting docker details using docker inspect
- Kyverno – Installation, Policies, Testing, Reporting, Monitoring, Security
- Complete Kubernetes Project Step By Step
- Introduction to Kubernetes Objects