A Kubernetes manifest file is a YAML or JSON file that is used to describe the desired state of Kubernetes resources in a cluster. A manifest file contains a set of instructions that Kubernetes can use to create, modify, or delete resources in the cluster.
Here are the key components of a Kubernetes manifest file:
API Version: The apiVersion field specifies the Kubernetes API version that is used by the manifest file. This field is required for all resources in the manifest file.
apiVersion: apps/v1
Kind: The kind field specifies the type of Kubernetes resource that is being defined in the manifest file. This field is required for all resources in the manifest file.
kind: Deployment
Metadata: The metadata field contains information about the resource, such as its name, labels, and annotations.
metadata:
name: my-app
labels:
app: my-app
annotations:
build: 1
Spec: The spec field contains the specification for the Kubernetes resource, including the desired state of the resource and any configuration settings.
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: my-image:latest
ports:
- containerPort: 80
The spec field for a Deployment, for example, contains information about the desired number of replicas, the selector used to identify the Pods in the Deployment, and the Pod template that specifies the container image and configuration.
In addition to these key components, a Kubernetes manifest file may also include other fields and settings that are specific to the type of resource being defined. For example, a Service resource may include a type field that specifies the type of Service to create, while a ConfigMap resource may include a data field that specifies the key-value pairs to include in the configuration.
Hereβs an example of a simple Kubernetes manifest file that defines a Deployment resource:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: my-image:latest
ports:
- containerPort: 80
This manifest file defines a Deployment resource called my-app that has three replicas and uses the container image my-image:latest with a port of 80.
In conclusion, a Kubernetes manifest file is a YAML or JSON file that is used to describe the desired state of Kubernetes resources in a cluster. The key components of a manifest file include the API version, the kind of resource being defined, the metadata for the resource, and the specification for the resource. By understanding the key components of a Kubernetes manifest file, you can create, modify, or delete resources in a Kubernetes cluster with ease.