October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Kubernetes YAML: Create, Apply, and Verify a Deployment Safely

A practical guide to Kubernetes manifests: understand apiVersion, kind, metadata, and spec; create a Deployment; check your cluster context; and apply and inspect changes with kubectl.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Kubernetes YAML manifest describes an API object and the state you want the cluster to maintain. To apply one safely, check that kubectl is connected to the intended cluster, review the manifest, preview its changes when appropriate, and run kubectl apply -f. A Deployment is a useful first example because it manages the desired number of application Pods—but it does not, by itself, make an application reachable from outside the cluster.

What is a Kubernetes YAML file?

A Kubernetes YAML file, often called a manifest, is a serialized description of a Kubernetes API object and its desired state. Kubernetes documentation puts the convention plainly: “By convention, manifests are YAML (you could also use JSON format).” (Kubernetes: Objects In Kubernetes)

As an Amazon Associate I earn from qualifying purchases.

Rather than issuing a separate command for each change, you declare the configuration in a file, keep it under version control, and use kubectl apply to send it to the cluster through the Kubernetes API. Kubernetes reconciles the declared configuration with the object it manages. The four fields commonly found at the top of a manifest are:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • apiVersion: the API group and version used to describe the object.
  • kind: the type of object, such as Deployment.
  • metadata: identifying information, commonly including a name and labels.
  • spec: the desired configuration. Its fields depend on the object’s kind; it is not a universal, identical block across Kubernetes resources.

What does apiVersion mean in Kubernetes YAML?

apiVersion tells Kubernetes which version of the API to use when interpreting the object definition. Different kinds use different API groups and versions; for example, the Deployment below uses apps/v1. Do not assume that one version applies to every kind. Consult the API reference for the cluster version you use, or inspect available fields with kubectl explain.

How do I create a Kubernetes deployment YAML file?

Create a plain-text file named deployment.yaml. This example declares a Deployment with two replicas. The image, replica count, namespace, and labels are choices to adapt to your application and cluster; verify that the image is available to the cluster and that the selected API is appropriate for your environment.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: default
  labels:
    app: web
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginx:1.27

The selector under spec identifies which Pods this Deployment manages. Its matchLabels value must match the labels on the Pod template; here, both use app: web. The template describes the Pods the Deployment creates, including the container name and image. replicas: 2 declares the desired number of instances, which the Deployment controller works to maintain. Kubernetes’ Deployment documentation explains this workload pattern: Deployments.

Fields and constraints vary by resource kind. To explore a field before adding it, use kubectl explain deployment.spec or consult the API reference that matches your Kubernetes version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What should I check before applying a manifest?

kubectl is the command-line client for communicating with the cluster’s control plane through the Kubernetes API. When it runs outside a cluster, it uses kubeconfig settings, including the current context and credentials. A valid YAML file alone does not establish a connection or ensure that commands target the intended cluster. Kubernetes’ kubectl reference describes the client, and its kubeconfig documentation explains cluster access configuration.

  1. Use a cluster that is running and that you are authorized to change. For learning, choose a safe, non-production environment.
  2. Check which context is active with kubectl config current-context. If it is not the intended context, select the correct one before continuing.
  3. Review the file for the intended namespace, image, labels, selector, and replica count. Treat a manifest change as a change to cluster state.
  4. Preview the proposed differences with kubectl diff -f deployment.yaml. Review the output before applying; the preview is not a substitute for confirming the target context.

Keep manifests in source control so changes can be reviewed and tracked. The Kubernetes documentation recommends declarative resource management with configuration files rather than relying on imperative commands as the ongoing workflow: Declarative Management of Kubernetes Objects Using Configuration Files.

How do I apply a YAML file in Kubernetes?

When the context and manifest are correct, apply the file with:

kubectl apply -f deployment.yaml

The command accepts YAML or JSON. It creates the resource if it does not exist and updates it when it does. For this first example, use a single file; as related manifests accumulate, kubectl apply -f can also target a directory, while kubectl apply -k applies a Kustomize directory. See the kubectl apply command reference for supported forms.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

After applying, inspect the object and its Pods:

kubectl get deployment web -n default
kubectl get pods -n default
kubectl describe deployment web -n default

These commands report what the cluster sees; use their output to check the Deployment’s status and investigate events or other problems. If you edit the manifest, repeat the review-and-preview process, then apply the changed file. Avoid treating a successful local edit—or even a successful apply—as proof that the workload is healthy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What a Deployment does not provide

A Deployment manages workload instances; it does not provide ordinary access to those Pods from outside the cluster. Pods are private to the cluster by default. For normal service-based access, create a Kubernetes Service, then configure any external exposure needed for your environment. The exposure mechanism depends on the Service configuration and cluster environment. See the Kubernetes documentation on Services.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.