Kubernetes Objects Tutorial – Let’s understand it in an easy way. In this blog post, I will help you to understand kubernetes objects and how we can express those in the .yaml file. Let’s enjoy our post.
Kubernetes Objects are persistent entities in the Kubernetes system. Kubernetes uses these entities to represent the state of your cluster. Specifically, they can describe:
- What containerized applications are running (and on which nodes)
- The resources available to those applications
- The policies around how those applications behave, such as restart policies, upgrades, and fault-tolerance
Once the kubernetes object is created, the Kubernetes system will check it constantly to make sure that object exists.
Kubernetes Objects Spec and Status
Every Kubernetes object includes 2 nested object fields that describe the object’s configuration:
- Object spec: describe the characteristics of the object
- Object status: describe the actual state of the object
For example, a Kubernetes Deployment is an object that can represent an application running on your cluster.
- Object spec: 3 replicas of the application
- Object status: 3 replicas are running or 2 replications are running….
Kubernetes Objects Example
Here’s an example
.yaml file that shows the required fields and objects spec for a Kubernetes Deployment:
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80
$ kubectl apply -f https://k8s.io/docs/user-guide/nginx-deployment.yaml --record
The output is similar to this:
deployment "nginx-deployment" created
Required Fields To Create Kubernetes Objects
apiVersion– Which version of the Kubernetes API you’re using to create this object
kind– What kind of object you want to create
metadata– Data that helps uniquely identify the object, including a
namestring, UID, and optional
You’ll also need to provide the object
spec field. The precise format of the object
spec is different for every Kubernetes object, and contains nested fields specific to that object.
Latest posts by admin (see all)
- Install and Running Supervisord in virtualenv python 2.7 - January 24, 2019
- Urgent fix: Briefly unavailable for scheduled maintenance. Check back in a minute. - January 22, 2019
- Change WordPress post date format to time ago - January 21, 2019