Pods YAML Walkthrough

MrDevSecOps
3 min readFeb 13, 2022

The simplest way to create a pod using the kubectl command but it is ideal for quick testing and development but is not recommended for production.

Since writing an object configuration in JSON is a bit more complex than YAML, so we’ll stick with YAML.

This definition file always contains four top-level fields, the API version, kind, metadata, and spec.

apiVersion:

  • This refers to the version of Kubernetes.
  • API version consists of two things group name and Version.
  • There are several versions, and several objects are introduced with each version.
  • Some common ones are v1, apps/v1, and extensions/v1beta1.
  • On the right-hand side, you can see the different types of values
  • You can check out the below command for the list of versions.
$ kubectl api-versions

Kind:

  • This is the type of Kubernetes object. In this case (the example above), we’re creating a pod.
  • You can see the other types of objects that we create commonly on the right side here.
  • You can check out the below command for the list of kinds.
$ kubectl api-resources | awk '{print $5}'

Metadata:

  • The metadata houses information that describes the object briefly.
  • The information in the metadata usually contains the name you want to give the object (pod in our case), the labels, and the annotation.
  • name the object is the only mandatory field and the remaining are optional.
  • You can check out the official Kubernetes documentation for the metadata field.

Spec:

  • The spec section is where we define containers that will run inside the pod.
  • For this example, we are deploying a single Nginx container with its latest image. Here we specify
  • The image of the application you want to run in your pods.
  • The name of the container that you’ll run in your pod.
  • ContainerPort is the port of your application in your container and the environment variable inside the containers.

That’s about the basic structure object configuration file.

Kind vs API Version

Above is the kind and respect to API Version mapping here.

All these objects are grouped based on the functionality of the respective objects.

--

--

MrDevSecOps

Integrating security into the software development lifecycle.