Skip to content

Deploy your first app

This guide takes a container image and gets it running on Kubernetes as a Deployment, then exposes it inside the cluster with a Service. The steps work on any conformant cluster, for example a shoot from your own Gardener landscape or a cluster I run for you.

Download your cluster’s kubeconfig and confirm you can reach it:

Terminal window
export KUBECONFIG=~/Downloads/paasbox-kubeconfig.yaml
kubectl get nodes

You should see your nodes listed as Ready.

Keep your app’s objects together in their own namespace:

Terminal window
kubectl create namespace demo

A Deployment runs and supervises your container, replacing Pods that crash or get rescheduled. Save this as deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
name: web
namespace: demo
spec:
replicas: 2
selector:
matchLabels: { app: web }
template:
metadata:
labels: { app: web }
spec:
containers:
- name: web
image: nginxdemos/hello:plain-text
ports:
- containerPort: 80
resources:
requests: { cpu: 50m, memory: 64Mi }
limits: { cpu: 250m, memory: 128Mi }

Apply it and watch the Pods come up:

Terminal window
kubectl apply -f deployment.yaml
kubectl -n demo get pods -w

Always set resource requests. They tell the scheduler how much CPU and memory your Pods need. That is what lets the cluster place more workloads on fewer nodes, which is where the savings come from.

A Service gives your Pods one stable address inside the cluster, load-balanced across replicas:

apiVersion: v1
kind: Service
metadata:
name: web
namespace: demo
spec:
selector: { app: web }
ports:
- port: 80
targetPort: 80
Terminal window
kubectl apply -f service.yaml

Port-forward the Service to your machine and hit it:

Terminal window
kubectl -n demo port-forward service/web 8080:80
# in another terminal:
curl localhost:8080

You should get a response from the app. 🎉

Terminal window
kubectl delete namespace demo