Overview

3 Deploying your first application on Kubernetes

This chapter presents a hands-on path from standing up a Kubernetes cluster to operating a simple web application on it. It compares lightweight local options (Docker Desktop’s single-node Kubernetes, Minikube, and kind) with managed, multi-node offerings in the cloud (notably Google Kubernetes Engine and Amazon Elastic Kubernetes Service), and explains why newcomers often start with local tools while production systems typically use managed clusters. It then introduces kubectl—the CLI for interacting with the Kubernetes API—showing how to install it, configure access, verify cluster health, and optionally use a web dashboard, while emphasizing that kubectl remains the primary and most capable interface.

With a cluster and kubectl ready, the chapter walks through deploying the sample Kiada application using an imperative workflow: create a Deployment that describes the desired application image and replica count, let Kubernetes schedule and run Pods, and observe status via kubectl. It clarifies that Pods—not individual containers—are Kubernetes’ smallest deployable unit, and that Kubernetes reconciles desired and actual state by pulling container images and starting workloads. To make the app reachable, it creates a Service, typically of type LoadBalancer in cloud environments, and explains alternatives like node ports for local clusters that lack external load balancers. The result is a stable, single access point that forwards traffic to the backing Pods.

Finally, the chapter demonstrates horizontal scaling by increasing the Deployment’s replicas, showing how Kubernetes creates additional Pods and how the Service distributes requests across them. It distinguishes the logical view (Deployment, Pods, Service) from the physical view (nodes, load balancers, and networking) and stresses pod ephemerality: Pods can be replaced at any time, so clients should target the Service’s stable virtual IP rather than Pod IPs. In short, you learn to stand up a cluster, use kubectl, deploy and expose an application, and scale it out—relying on Kubernetes to reconcile state and route traffic reliably.

The Settings dialog box in Docker Desktop for Windows
Kubernetes running in Docker Desktop
Running a single-node Kubernetes cluster using Minikube
Running a multi-node Kubernetes cluster using kind
Your Kubernetes cluster in Google Kubernetes Engine
Interacting with a Kubernetes cluster
Screenshot of the Kubernetes web-based dashboard
The relationship between containers, pods, and worker nodes
How creating a Deployment object results in a running application container
What happens when you create a Service object of type LoadBalancer
Connection routing through a service’s node port
Load balancing across multiple pods backing the same service
Your deployed application consists of a Deployment, several pods, and a service.

Summary

  • Virtually all cloud providers offer a managed Kubernetes option. They take on the burden of maintaining your Kubernetes cluster, while you only use its API to deploy your applications.
  • You can also install Kubernetes in the cloud yourself, but this may not be the best idea until you master all aspects of managing Kubernetes.
  • You can install Kubernetes locally, even on your laptop, using tools such as Docker Desktop or Minikube, which run Kubernetes in a Linux VM, or kind, which runs the master and worker nodes as Docker containers and the application containers inside those containers.
  • Kubectl, the command-line tool, is the usual way you interact with Kubernetes. A web-based dashboard also exists, but it is not as stable and up to date as the CLI tool.
  • To work faster with kubectl, it is useful to create a short alias for it and enable shell completion.
  • An application can be deployed using kubectl create deployment. It can then be exposed to clients by running kubectl expose deployment. Horizontally scaling the application is trivial: kubectl scale deployment instructs Kubernetes to add new replicas or removes existing ones to reach the number of replicas you specify.
  • The basic unit of Deployment is not a container, but a pod, which can contain one or more related containers.
  • Deployments, Services, Pods, and Nodes are Kubernetes objects/resources. You can list them with kubectl get and inspect them with kubectl describe.
  • The Deployment object deploys the desired number of pods, while the Service object makes them accessible under a single, stable IP address.
  • Each service provides internal load balancing in the cluster, but if you set the type of service to LoadBalancer, Kubernetes will ask the cloud infrastructure it runs in for an additional load balancer to make your application available at a publicly accessible address.

FAQ

What are the easiest ways to run a local Kubernetes cluster, and how do they differ?Three popular options are: 1) Docker Desktop: one-click, single-node cluster on macOS/Windows; version may lag. 2) Minikube: single-node (usually in a VM), often newer Kubernetes; can run “without a VM” on Linux. 3) kind (Kubernetes in Docker): runs cluster nodes as containers, supports multi-node locally with minimal overhead—great for development and testing.
How do I enable and use the built-in Kubernetes in Docker Desktop?Open Docker Desktop Settings, select the Kubernetes tab, and turn on “Enable Kubernetes.” The first start pulls control plane images and can take several minutes. It’s a single-node setup that’s sufficient for most chapter exercises; you can list containers from your host Docker CLI and, if needed, explore the underlying VM using a privileged helper container.
How do I install and start Minikube, and check its status?Install Minikube via Homebrew (macOS), installer (Windows), or download the binary (Linux). Start with: minikube start. Check health with: minikube status. On Linux you can avoid a VM for lower overhead using: minikube start --vm-driver=none. Use minikube ssh to explore the node.
What is kind and how do I run multi-node clusters with it?kind runs Kubernetes nodes as Docker containers on your machine. Create a cluster with: kind create cluster. For multi-node, provide a small config (one control-plane, multiple worker roles) and run: kind create cluster --config your-config.yaml. List nodes with: kind get nodes. Use docker exec -it bash to enter a node; use crictl ps inside to list containers.
How can I create a managed cluster (GKE/EKS) and control costs?GKE: after installing gcloud, set a zone (gcloud config set compute/zone ...) and create a cluster (gcloud container clusters create kiada --num-nodes 3). Resize later, even to zero, to save costs (gcloud container clusters resize kiada --size 0). EKS: install eksctl and create a cluster (eksctl create cluster --name kiada --region --nodes 3 --ssh-access). Managed options provision real multi-node clusters for you.
How do I install kubectl, point it at my cluster, and make it convenient to use?Download kubectl for your OS and put it in PATH. kubectl reads kubeconfig from ~/.kube/config (or set KUBECONFIG to a custom path). Create a short alias (e.g., alias k=kubectl) and enable shell completion (source <(kubectl completion bash) and complete -o default -F __start_kubectl k) to speed up daily use.
How do I verify connectivity to the cluster and inspect nodes?Run kubectl cluster-info to confirm API server access. List nodes with kubectl get nodes and show more details with kubectl get nodes -o wide. For deep inspection use kubectl describe node to view capacity, conditions, and running components.
How do I deploy my first app and see the resulting Pods?Create a Deployment: kubectl create deployment kiada --image=luksa/kiada:0.1. Check status with kubectl get deployments. List Pods with kubectl get pods; a new Pod may be Pending while the image pulls, then transitions to Running. If something’s wrong (e.g., image pull errors), run kubectl describe pod and read the Events section.
How do I expose my app externally (LoadBalancer vs node port), and how do I access it in different environments?Create a Service: kubectl expose deployment kiada --type=LoadBalancer --port 8080. In clouds (e.g., GKE) an external IP appears; access via http://EXTERNAL-IP:8080. In local setups without a cloud LB (Minikube/kind), EXTERNAL-IP shows <pending>; use the nodePort shown in kubectl get svc (e.g., 8080:3xxxx) and connect to NODE_IP:nodePort. Shortcuts: Minikube users can run minikube service kiada (or --url). Docker Desktop often exposes at localhost:8080.
How do I scale the application and how is traffic distributed?Scale out with kubectl scale deployment kiada --replicas=3. The Service automatically load balances requests across all healthy Pods behind it. In the cloud there are two layers: the cloud load balancer spreads traffic across nodes, and the Kubernetes Service spreads traffic across Pods.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Kubernetes in Action, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Kubernetes in Action, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Kubernetes in Action, Second Edition ebook for free