Kubernetes YAML manifest structure¶
A Kubernetes YAML manifest is a configuration file used to define and manage Kubernetes resources. These files follow a standard structure containing four required top-level fields: apiVersion, kind, metadata, and spec.^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md]
Top-level Fields¶
The structure of a Kubernetes manifest is built upon the following four keys:
- apiVersion: Specifies the version of the Kubernetes API the resource belongs to^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
- kind: Indicates the type of Kubernetes object to be created (e.g.,
Pod,Service,Deployment,Ingress)^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md]1. - metadata: Stores data that helps uniquely identify the object, including its
nameandlabels^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md]. - spec: Defines the desired state of the resource, effectively "the specification" for that object^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
Common Sections¶
Metadata¶
The metadata field is essential for organizing and identifying resources. It typically includes:
* name: The unique identifier for the resource within a namespace^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
* labels: Key-value pairs attached to the object (e.g., app: foo)^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md]. Labels are used by selectors in other resources, such as a Service targeting a specific set of Pods^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
Spec¶
The spec section contains the actual configuration of the resource. Its content varies significantly depending on the kind:
* For Pods: It lists the containers to be run, including the image name, ports, and resource requirements^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
* For Ingress: It defines rules, hostnames, and backend services, often nested within an ingressClassName^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__TODO.md]2.
* For Services: It defines the type of service and the ports to expose.
Example: Pod Manifest¶
Below is an example of a Pod manifest illustrating the standard structure^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md]:
apiVersion: v1
kind: [Pod](<./pod.md>)
metadata:
name: foo
labels:
app: foo
spec:
containers:
- name: foo
image: mikehsu0618/foo
ports:
- containerPort: 8080
In this example:
* The metadata.labels field allows other resources to select this Pod^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
* The spec.containers field configures the container image and the port (containerPort) it exposes^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
Related Concepts¶
- Kubernetes
- Pod
- Kubernetes Ingress
- [[Service (Kubernetes)]]
Sources¶
- 400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md
- 400-devops__06-Kubernetes__devops-helm__helm-jenkins__TODO.md