What is a Kubernetes Manifest File

A Kubernetes Manifest files are the heart of Kubernetes. These plaintext configuration files describe how a pod’s containers should be run and connected to other objects, such as services or replication controllers.

Kubernetes uses a declarative model rather than an imperative model for Pod specification.

Each file is written in YAML format, which was chosen due to its widespread support from various tools and its level of readability by humans. An example Pod definition could look like this:

apiVersion: v1
kind: Pod 
metadata:
 name: nginx 
labels: 
  app : nginx 
spec : 
containers: 
  - name: nginx
    image: nginx

This file describes a Pod consisting of only one container, which will run the “nginx” binary and is labelled with the app “nginx”. This means that it belongs to the same namespace as all other objects that are labelled with this label. The rest of this article will focus on Kubernetes Pods.

There are several different ways in which you can specify what goes into your Pod definition, but if you want to learn about each field, please refer to the official documentation. Instead, I’ll walk through some examples below.

You can declare multiple containers in one Pod by specifying an array for the container spec instead of a list. For compatibility reasons, there’s also a deprecated multi-container syntax that you can still use, but it’s best to avoid using this if possible.

You can also use volume mounts to share directories between the container and the local disk. For example, this volume declaration would make all files under “/etc/nginx/” available to the nginx container on its standard path.

apiVersion: v1
kind: Pod 
metadata:
 name: nginx 
labels: 
  app : nginx 
spec : 
containers: 
  - name: nginx
    image: nginx
    volumeMounts: 
      - name: www 
        mountPath: /etc/nginx/

For more articles about Kubernetes, visit the category page.


Posted

in

by

Comments

2 responses to “What is a Kubernetes Manifest File”

  1. […] In our previous posts, we deeply a pod using kubectl, and we covered Kubernetes manifest file. […]

  2. […] the manifest file below (YAML), I have a deployment object that is an entry point to run a specific command when […]