Manifest
A manifest in the context of Kubernetes is a file that defines the desired state of a Kubernetes resource. These manifest files are typically written in YAML or JSON format and contain the configuration details for various Kubernetes objects, such as Pods, Deployments, Services, ConfigMaps, etc.
Key Components of a Kubernetes Manifest:
- apiVersion: Specifies the version of the Kubernetes API that you’re using to create this resource. It ensures that the resource conforms to the correct schema.
apiVersion: v1
- kind: Indicates the type of Kubernetes object you are defining (e.g., Pod, Deployment, Service).
kind: Pod
- metadata: Provides information about the object, such as its name, namespace, labels, and annotations.
metadata:
name: my-pod
namespace: default
labels:
app: myapp
- spec: Defines the desired state of the resource, specifying the details of the object. The contents of the
spec
section vary depending on the type of resource. For example, in a Pod manifest, thespec
might include information about the containers that the Pod should run:
spec:
containers:
- name: my-container
image: nginx:1.21
ports:
- containerPort: 80
Example of a Simple Kubernetes Manifest:
Here’s an example manifest file for a Pod:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: myapp
spec:
containers:
- name: my-container
image: nginx:1.21
ports:
- containerPort: 80
Usage of Manifests:
- Declarative Management: Kubernetes operates on a declarative model. You define the desired state of your application in a manifest, and Kubernetes works to ensure that the actual state matches the desired state. If there is a difference, Kubernetes automatically makes adjustments to align the actual state with the manifest.
- Reusability: Manifests can be reused across different environments, such as development, testing, and production, with appropriate modifications to the configuration.
- Version Control: Manifests can be stored in version control systems like Git, enabling you to track changes, collaborate with team members, and roll back to previous versions if needed.
Interacting with Manifests:
You can apply, update, or delete resources in a Kubernetes cluster using these manifests by interacting with the Kubernetes API through the kubectl
command-line tool.
- Applying a manifest:
kubectl apply -f my-manifest.yaml
- Deleting resources defined in a manifest:
kubectl delete -f my-manifest.yaml
- Viewing the current state of a resource:
kubectl get pod my-pod -o yaml
Manifests are central to Kubernetes operations, as they define the infrastructure and application deployments in a Kubernetes cluster.