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.
1. Point kubectl at your cluster
Section titled “1. Point kubectl at your cluster”Download your cluster’s kubeconfig and confirm you can reach it:
export KUBECONFIG=~/Downloads/paasbox-kubeconfig.yamlkubectl get nodesYou should see your nodes listed as Ready.
2. Create a namespace
Section titled “2. Create a namespace”Keep your app’s objects together in their own namespace:
kubectl create namespace demo3. Deploy the app
Section titled “3. Deploy the app”A Deployment runs and supervises your container, replacing Pods that crash
or get rescheduled. Save this as deployment.yaml:
apiVersion: apps/v1kind: Deploymentmetadata: name: web namespace: demospec: 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:
kubectl apply -f deployment.yamlkubectl -n demo get pods -wAlways 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.
4. Expose it with a Service
Section titled “4. Expose it with a Service”A Service gives your Pods one stable address inside the cluster, load-balanced across replicas:
apiVersion: v1kind: Servicemetadata: name: web namespace: demospec: selector: { app: web } ports: - port: 80 targetPort: 80kubectl apply -f service.yaml5. Try it
Section titled “5. Try it”Port-forward the Service to your machine and hit it:
kubectl -n demo port-forward service/web 8080:80# in another terminal:curl localhost:8080You should get a response from the app. 🎉
Next steps
Section titled “Next steps”- Run more copies and let the cluster scale them: Scale & autoscale workloads.
- Serve it from the public internet over HTTPS: Expose your app with Ingress & TLS. It builds directly on the app you just deployed.
Clean up
Section titled “Clean up”kubectl delete namespace demo