iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
A Kubernetes YAML file describes the desired state of an API object; applying it asks Kubernetes to create or update that object. For a first workload, define a Deployment, check that kubectl is pointed at the intended cluster, preview the change, then apply and inspect it. A Deployment manages Pods, but it does not by itself make an application reachable from outside the cluster.
What is a Kubernetes YAML file?
A Kubernetes manifest is a serialized description of a Kubernetes API object and its desired state. YAML is the customary format, though Kubernetes also accepts JSON. As the Kubernetes documentation explains, “By convention, manifests are YAML (you could also use JSON format).”
A typical object manifest has four top-level fields:
Recommended Free Tools
apiVersionidentifies the API group and version used to describe the object.kindnames the type of object, such asDeploymentorService.metadataholds identifying information, commonly the object’s name and labels.specdescribes the desired configuration. Its fields depend on the object’s kind; a Deployment and a Service do not share one universal spec schema.
To discover fields for a particular resource, use kubectl explain or consult the Kubernetes API reference. For example, kubectl explain deployment.spec asks kubectl for the Deployment spec’s field information.
#1 Best Overall
What should I check before applying a manifest?
You need a running Kubernetes cluster, an installed kubectl client, and a kubeconfig context with credentials for that cluster. Kubectl communicates with the control plane through the Kubernetes API; editing a local file alone does not establish a cluster connection. The Kubernetes tools documentation covers installing kubectl, and its kubeconfig documentation explains cluster access and contexts.
Before changing anything, inspect the context that kubectl will use:
kubectl config current-context
If that is not the intended learning cluster, select the correct context with kubectl config use-context CONTEXT_NAME, replacing CONTEXT_NAME with a context listed by kubectl config get-contexts. Use a non-production learning environment for your first experiments so an accidental apply cannot alter important workloads.
How do I create a Kubernetes deployment YAML file?
Create a file named deployment.yaml with a Deployment manifest such as this one:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-demo
namespace: default
labels:
app: web-demo
spec:
replicas: 2
selector:
matchLabels:
app: web-demo
template:
metadata:
labels:
app: web-demo
spec:
containers:
- name: web
image: nginx:1.27
The values here are example choices, not universal recommendations: apps/v1 is the Deployment API version shown in the official example, web-demo is the example resource and container name, default is the chosen namespace, 2 is the desired replica count, and nginx:1.27 is an example image tag. Adapt the image to one you are permitted to use and that is appropriate for your cluster. Check current Kubernetes documentation and your cluster’s version when selecting API versions and images; this example is not a compatibility guarantee.
The Deployment’s spec.selector.matchLabels must match the labels in spec.template.metadata.labels. The selector tells the Deployment which Pods it manages, while the template supplies the Pod definition, including its container image. The controller works toward the desired number of instances and replaces managed Pods when necessary. For an application workload, this management is why a Deployment is generally a more useful starting point than creating a standalone Pod.
How do I apply a YAML file in Kubernetes?
After saving the manifest and confirming the active context, preview and apply the file:
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →-
Preview the proposed change with
kubectl diff -f deployment.yaml. Review the output and confirm that the target resource and settings are what you intend. -
Apply the declared configuration with
kubectl apply -f deployment.yaml. -
Check the Deployment with
kubectl get deployment web-demoand inspect its details withkubectl describe deployment web-demo. -
Check the Pods managed by it with
kubectl get pods -l app=web-demo. If they are not ready, the Deployment description and Pod status provide useful clues for further diagnosis.Free tools Windows power users keep installed
One-click scans. No signup required.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
kubectl apply sends the declared configuration to the cluster through the Kubernetes API. It creates the resource if it does not exist and updates it when it does. The kubectl apply reference also documents applying directories, multiple file arguments, and standard input; when related resources accumulate, a Kustomize directory can be applied with kubectl apply -k DIRECTORY.
How should I manage changes after the first apply?
Keep manifest files in source control so the desired configuration can be reviewed, tracked, and restored alongside the changes that produced it. For each update, edit the file, run kubectl diff -f deployment.yaml to see what would change, review the diff, and then run kubectl apply -f deployment.yaml. This file-based declarative workflow makes the configuration the record of what you intend, rather than relying on a sequence of untracked manual changes. The Kubernetes object-management documentation describes declarative management with configuration files.
Does applying a Deployment make the application reachable?
No. A Deployment manages workload instances; it is not the normal network-access mechanism for those Pods. Pods are private within the cluster by default. To provide stable service-based access, define a Kubernetes Service that selects the relevant Pods. Whether that Service is reachable from outside the cluster depends on its configuration and the cluster environment; additional exposure configuration may be needed. Applying only the Deployment does not mean the application is live on the internet. See the Kubernetes Service documentation for how Services provide network access to a set of Pods.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

