Deploying the first image
This guide will walk you through the process of rolling out your first application in your cluster – from deployment and release right through to testing.
Prerequisites
- A cluster with the status Running
- A downloaded configuration file and a verified connection; see Connecting to the cluster
kubectlinstalled
First, check that the connection is working:
kubectl get nodes
All nodes should have the status Ready.
1. Create a deployment
A deployment specifies which image is to run in how many instances. Create the file deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:stable
ports:
- containerPort: 80
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 256Mi
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 10
Key information:
replicas– Number of instances. Two replicas ensure that the application remains accessible during upgrades.resources.requests– Resources reserved by the scheduler for placement.resources.limits– Upper limit that a container must not exceed.readinessProbe– Ensures that only ready pods receive traffic.
Roll out the deployment:
kubectl apply -f deployment.yaml
2. Check the rollout
# Status des Rollouts
kubectl rollout status deployment web
# Laufende Pods
kubectl get pods -l app=web
Expected output:
NAME READY STATUS RESTARTS AGE
web-6d4cf56db6-8xk2p 1/1 Running 0 30s
web-6d4cf56db6-tz9vn 1/1 Running 0 30s
If a pod gets stuck in Pending or ImagePullBackOff, the following commands will reveal the cause:
kubectl describe pod <pod-name>
kubectl logs <pod-name>
3. Publish the application
A service makes the pods accessible via a fixed address.
Services of type LoadBalancer are currently not available – no Cloud Controller Manager has been set up to assign external addresses. Such a service remains permanently with EXTERNAL-IP: <pending>.
Instead, use NodePort for external access or kubectl port-forward for local testing.
Option A: Service of Type Load Balancer
A Service of type LoadBalancer is assigned an external IP address through the Cloud Controller Manager. Check the Service status to verify whether the IP address has been assigned.
Create the file service.yaml:
apiVersion: v1
kind: Service
metadata:
name: web
labels:
app: web
spec:
type: LoadBalancer
selector:
app: web
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
How to use:
kubectl apply -f service.yaml
Check the service and the assigned port:
kubectl get service web
The external IP address should be available after a short while.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)
web LoadBalancer 10.96.173.63 <pending> 80:30292/TCP
Call via external IP address or add also a DNS entry for this service:
curl http://<external-node-ip>
Option B: Port forwarding for local testing
For a quick test, local port forwarding is sufficient. The service can be of type ClusterIP (the default if type is not specified):
kubectl port-forward service/web 8080:80
The application can then be accessed via http://localhost:8080. The redirection remains in place for as long as the command is running.
4. Scaling the application
kubectl scale deployment web --replicas=4
To ensure that the replicas are distributed across different nodes, add topologySpreadConstraints – see High Availability.
5. Tidying up
To remove test resources that are no longer required, use:
kubectl delete -f service.yaml
kubectl delete -f deployment.yaml
If you use NodePort as the Service type, the selected port is reserved on all Worker Nodes. Delete any Services you no longer need to free up the ports for other applications.
Next steps
- Install Ingress Controller – for running multiple HTTP services behind a single address
- Enable HTTPS – for encrypted connections
- Storage Features – storage options and stateful applications
- Horizontal Pod Autoscaling – for load-based scaling