pod-definition.yaml
Note: Pod YAML also Deployment, Service, ReplicaSet, and others follow the below four top-level fields, these are the top-level or root-level properties.
apiVersion: kind: metadata: spec: |
apiVersion: this version depends on what we are trying to create we must use the right API version. Such as POD for version will be v1, service for version will be v1, ReplicaSet for version will be apps/v1, and Deployment for apps/v1
KInd | Version |
POD | v1 |
Service | v1 |
ReplicaSet | apps/v1 |
Deployment | apps/v1 |
Kind: This refers to the type of object we are trying to create which in this case happens, such as kind can be a Pod, Deployment, Service, or ReplicaSet.
Metadata: The metadata is data about the object like its name, labels, etc. Under the metadata, everything is intended to the right a little bit and so under the things are children of metadata.
Spec: This describes the desired state of the pod
Here’s a full example of a Pod YAML file:
apiVersion: v1 kind: Pod metadata: name: example-pod Labels: app: example spec: containers: – name: example-container image: nginx ports: – containerPort: 80 |
Let’s break down the key fields:
- apiVersion: Specifies the version of the Kubernetes API you’re using.
- kind: Specifies the type of Kubernetes object, in this case, a Pod.
- metadata: Contains metadata about the Pod, such as its name and labels.
- name: The name of the Pod.
- labels: Key-value pairs used to organize and select subsets of objects.
- spec: Describes the desired state of the Pod.
- containers: An array of containers that should be run in this Pod.
- name: The name of the container.
- image: The Docker image to run within the container.
- ports: Specifies ports that the container exposes.
- containerPort: The port number the container listens on.
- containers: An array of containers that should be run in this Pod.
great