Kubernetes Manifest Fundamentals
Kubernetes manifests, also known as Kubernetes YAML files or Kubernetes configuration, are the foundation for deploying and managing applications on a Kubernetes cluster. These manifests define the desired state of your Kubernetes resources, such as Pods, Deployments, Services, and more.
In this section, we will explore the fundamentals of Kubernetes manifests, including their structure, common resource types, and how to create and apply them.
Understanding Kubernetes Manifests
Kubernetes manifests are written in YAML (YAML Ain't Markup Language) format, which is a human-readable data serialization format. These manifests describe the desired state of your Kubernetes resources, and the Kubernetes control plane will work to ensure that the actual state matches the desired state.
A typical Kubernetes manifest consists of the following key elements:
apiVersion: <api-version>
kind: <resource-type>
metadata:
name: <resource-name>
## other metadata, such as labels, annotations, etc.
spec:
## configuration details for the resource
The apiVersion
field specifies the Kubernetes API version to use, the kind
field specifies the type of Kubernetes resource, and the metadata
and spec
fields contain the resource's configuration details.
Common Kubernetes Resource Types
Some of the most commonly used Kubernetes resource types include:
- Pods: The basic unit of deployment in Kubernetes, representing one or more containers running together.
- Deployments: Manage the lifecycle of Pods, ensuring a desired number of replicas are running.
- Services: Provide a stable network endpoint to access your application's Pods.
- ConfigMaps: Store configuration data that can be used by Pods.
- Secrets: Store sensitive data, such as passwords or API keys, that Pods can use.
Here's an example of a simple Kubernetes Deployment manifest:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
This manifest creates a Deployment named nginx-deployment
that runs three replicas of the Nginx web server.
Applying Kubernetes Manifests
To apply a Kubernetes manifest, you can use the kubectl apply
command:
kubectl apply -f path/to/manifest.yaml
This will create or update the resources defined in the manifest on your Kubernetes cluster.
By understanding the fundamentals of Kubernetes manifests, you can effectively manage the deployment and configuration of your applications on a Kubernetes cluster.