K8S Resource YAML Configuration
November 8, 2024About 2 min
K8S Resource YAML Configuration
Parameter Name | Type | Description |
---|---|---|
apiVersion | String | The version of the K8S API, which can be queried with the kubectl api versions command |
kind | String | The resource type and role defined in the YAML file |
metadata | Object | Metadata object, containing the following properties: |
metadata.name | String | Name of the metadata object, for example, the pod name |
metadata.namespace | String | The namespace of the metadata object |
spec | Object | Detailed specification of the object |
spec.containers[] | List | List of containers defined in the Spec object |
spec.containers[].name | String | Name of a specific container in the list |
spec.containers[].image | String | The image name required for a specific container in the list |
spec.containers[].imagePullPolicy | String | Defines the image pull policy, can be Always , Never , or IfNotPresent :- Always (default): Always attempt to pull the image.- Never : Use only local images.- IfNotPresent : Use the local image if available, otherwise pull from the repository. |
spec.containers[].command[] | List | Specifies the container's startup command. It is an array, so multiple commands can be specified. If not specified, the command used in the image is used. |
spec.containers[].args[] | List | Specifies the container's startup command arguments. Multiple arguments can be specified as an array. |
spec.containers[].workingDir | String | Specifies the working directory for the container |
spec.containers[].volumeMounts[] | List | List of volume mount configurations for the container |
spec.containers[].volumeMounts[].name | String | Specifies the name of the volume that the container can mount |
spec.containers[].volumeMounts[].mountPath | String | Specifies the path where the container mounts the volume |
spec.containers[].volumeMounts[].readOnly | Boolean | Sets the read/write mode of the volume mount path, true or false (default is read-write) |
spec.containers[].ports[] | List | List of ports required by the container |
spec.containers[].ports[].name | String | The name of the port |
spec.containers[].ports[].containerPort | String | The port number the container needs to listen on |
spec.containers[].ports[].hostPort | String | The port number on the host that the container needs to listen on (defaults to the same as containerPort ). Setting hostPort means that the same pod cannot be started again on the same host (due to port conflict). |
spec.containers[].ports[].protocol | String | The port protocol, can be TCP or UDP (default is TCP ) |
spec.containers[].env[] | List | List of environment variables to be set for the container before it starts |
spec.containers[].env[].name | String | The name of the environment variable |
spec.containers[].env[].value | String | The value of the environment variable |
spec.containers[].resources | Object | Defines resource limits and requests for the container |
spec.containers[].resources.limits | Object | Specifies resource limits for the container during runtime |
spec.containers[].resources.limits.cpu | String | CPU limit, specified in cores, used for the docker run --cpu-shares parameter |
spec.containers[].resources.limits.memory | String | Memory limit, specified in MiB or GiB |
spec.containers[].resources.requests | Object | Defines the resource requests for the container during startup and scheduling |
spec.containers[].resources.requests.cpu | String | CPU request, specified in cores, defines the initial amount available when the container starts |
spec.containers[].resources.requests.memory | String | Memory request, specified in MiB or GiB, defines the initial amount available when the container starts |
spec.restartPolicy | String | Defines the restart policy for the pod, possible values: Always , OnFailure , Never (default is Always ):- Always : If the pod terminates, it will be restarted regardless of how it was terminated.- OnFailure : The pod is restarted only if it terminates with a non-zero exit code.- Never : The pod will not be restarted after termination. |
spec.nodeSelector | Object | Defines label selectors for filtering nodes, specified in key: value format |
spec.imagePullSecrets | Object | Defines the name of the secret used for image pulls, specified in name: secretkey format |
spec.hostNetwork | Boolean | Defines whether to use the host network mode, default is false . Setting this to true means the container uses the host network instead of Docker's bridge network. This will prevent multiple replicas of the same container from running on the same host. |