Kubernetes resource manifest structure¶
A Kubernetes resource manifest is a configuration file written in YAML or JSON that defines the desired state of a Kubernetes resource, such as a Pod, [[Service]], or [[Deployment]].^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md]
Structure¶
Every Kubernetes manifest typically contains four top-level fields:
- apiVersion: Specifies the version of the Kubernetes API the object belongs to (e.g.,
v1).^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md] - kind: Indicates the type of Kubernetes object to be created (e.g.,
Pod).^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md] - metadata: Holds data that helps uniquely identify the object, including its
nameandlabels[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md][400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md#L62-L63].- name: A unique string assigned to the object (e.g.,
foo).^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md] - labels: Key-value pairs attached to the object used for organization and grouping[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md][400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md#L64-L66]. These allow other components, like Services or Deployments, to identify and select specific sets of objects using selectors.
- name: A unique string assigned to the object (e.g.,
- spec: Defines the desired state of the resource^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md]. The content of this field varies depending on the
kindof resource being created.
Spec Configuration for Pods¶
For a Pod, the spec section is primarily used to define container attributes^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md]:
- containers: A list of container configurations to be run within the Pod^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
- name: The specific name of the container^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
- image: The location of the container image to pull (e.g., a Docker Hub path)^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
- ports: A list of network ports to expose^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
- containerPort: Specifies the port the container listens on for traffic^[400-devops__06-Kubernetes__k8s-ithelp__Day6__README.md].
Example Manifest¶
The following example demonstrates a manifest for a simple Pod:
apiVersion: v1
kind: Pod
metadata:
name: foo
labels:
app: foo
spec:
containers:
- name: foo
image: mikehsu0618/foo
ports:
- containerPort: 8080
Related Concepts¶
- Pod
- [[Service]]
- [[Deployment]]