Deploy a Hello World Service on Kubernetes with YAML: Step‑by‑Step Guide
This tutorial walks through deploying a simple Hello World application on a Kubernetes cluster using YAML files, covering Deployment and Service definitions, key fields such as name, selector, labels, image, ports, and how to expose the service via a NodePort.
Assuming you already have a functional Kubernetes (K8s) cluster with at least one worker node, you can optionally create a local cluster with Minikube if needed.
Deployment is a core workload type that defines a set of Pods and how they are managed. A Pod is the smallest unit for deploying containers and may contain one or more containers.
Kubernetes uses YAML for configuration. When you run kubectl apply -f deployment.yaml, the YAML is parsed, converted to JSON, and stored in etcd; the corresponding controller then creates the resources.
A minimal Deployment YAML includes fixed fields such as apiVersion, kind, and spec. Key sections are:
name : the Deployment’s identifier; omission causes an error.
selector and labels : link the Deployment to its Pods; mismatched selectors and labels also trigger errors.
image : specifies the container image to run (e.g., digitalocean/flask-helloworld:latest).
ports : exposes at least one port if the service needs external access.
After applying the Deployment YAML, the system creates a Deployment named hello‑world, which spawns a Pod (e.g., hello‑world-6466c45588-fp6hk) scheduled on a node (e.g., k8s‑large‑1665988579).
Service provides a stable entry point for a group of Pods. It uses a label selector to match Pods and can expose them via different types; this example uses NodePort , allowing access through any node’s IP plus the allocated port.
A Service YAML also contains fixed fields like kind and spec. Important fields are:
name : the Service’s identifier.
type : set to NodePort to expose the service on a node port.
ports :
port : the external port clients connect to.
targetPort : the container’s port.
nodePort : a port in the 30000‑32767 range assigned by the cluster.
selector : matches the Pods created by the Deployment.
Visual tools show that a Service named hello‑world of type NodePort is created with IP 10.43.36.77, linking Service port 80 to nodePort 30008. Accessing any node’s IP at :30008 reaches the Hello World application.
The article includes several diagrams illustrating the relationship between Deployment, Pod, and Service, and screenshots of the resources as they appear in the Kubernetes dashboard.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Network Intelligence Research Center (NIRC)
NIRC is based on the National Key Laboratory of Network and Switching Technology at Beijing University of Posts and Telecommunications. It has built a technology matrix across four AI domains—intelligent cloud networking, natural language processing, computer vision, and machine learning systems—dedicated to solving real‑world problems, creating top‑tier systems, publishing high‑impact papers, and contributing significantly to the rapid advancement of China's network technology.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
