Kubernetes 101 : Generating Yaml files for Kubernetes objects and environment variables



A ready to use Yaml file:

To create a Yaml file describing a pod for example without creating the pod object, we use the below command: 


The output is written in the "deploy-1.yaml" file.

--dry-run: this option instructs kubernetes to create the Yaml file that represents the pod without creating the pod itself.
The resulting Yaml file is saved in "deploy-1.yaml".

We can then change the file to suit our needs, then we run the below command to create the kubernetes object (pod):


Pods and containers:

Usually a pod "hosts" one container as shown in the Yaml file below:


But it could also "host" more than one container as we can see in the example below (debian and ubuntu):


Environment Variables:

Environment variables are one way we could use to pass information to containers when they start running.
Below is an example of an environment variable:



We can see that the "debian" container has access to the "sleep-time" variable. It can use it, for example as an argument to a specific program.
Environment variables are set at the container level as we can see above.

Remark:

We can check the environment variable of different images by looking at the specifications of each image in their registry - docker hub for example -. 

For the "mongoDB" image, we can find the following environment variables that we could pass to a "mongoDB" pod for example:
  • MONGO_INITDB_ROOT_USERNAME
  • MONGO_INITDB_ROOT_PASSWORD

Comments

Leave as a comment:

Archive