K8s by Example: Hello World
| Let’s deploy a web server and access it. This is the Kubernetes equivalent of “Hello World” - create a Deployment, expose it with a Service, and make a request. |
| hello.yaml | |
| A Deployment manages replicas of your application. It ensures the desired number of pods are always running. | |
| Run 2 replicas. The selector must match the pod template labels - this is how the Deployment knows which pods it owns. | |
| The template defines the pods. Each pod runs an nginx container that serves a default welcome page on port 80. | |
| A Service provides a stable endpoint to access the pods. | |
| The selector routes traffic to pods with matching labels. Port 80 on the Service forwards to port 80 on the pods. | |
| terminal | |
| Apply the manifest. Kubernetes creates the Deployment, which creates a ReplicaSet, which creates the pods. | |
| terminal | |
| Check the pods are running. The random suffix in the name comes from the ReplicaSet. | |
| terminal | |
| The Service gets a cluster IP. This IP is stable - pods can come and go, but the Service IP stays the same. | |
| terminal | |
| Test the Service from inside the cluster. We spin up a temporary pod with curl and hit the Service by name. DNS resolves | |
| terminal | |
| To access from your machine, use port-forward. This tunnels localhost:8080 to the Service. Open | |
| terminal | |
| Clean up by deleting everything defined in the manifest. | |
Index | Use arrow keys to navigate