A Kubernetes Deployment keeps the pods for a microservice running. Unlike a standalone pod, it monitors the application and replaces an instance if it crashes or stops responding. A Service has a different job: it exposes the microservice through DNS and, when configured to do so, outside the cluster. section 6.4.3 section 6.15
Listing 6.2 Deploying our microservice to Kubernetes on Azure
apiVersion: apps/v1
kind: Deployment
metadata:
name: video-streaming
spec:
replicas: 1
selector:
matchLabels:
app: video-streaming
template:
metadata:
labels:
app: video-streaming
spec:
containers:
- name: video-streaming
image: bmdk1.azurecr.io/video-streaming:1 #1
imagePullPolicy: IfNotPresent #2
env:
- name: PORT
value: "4000"
---
apiVersion: v1
kind: Service
metadata:
name: video-streaming
spec:
selector:
app: video-streaming
type: LoadBalancer #3
ports:
- protocol: TCP
port: 80
targetPort: 4000
The YAML declares one replica, matches the Deployment’s selector to its pod-template label, and runs a versioned container image. A separate Service selects the same label and routes port 80 to the container’s port 4000. section 6.11.4 section 6.8.3
To deploy and check a microservice:
- Build and publish a versioned image, then set the image URL in deploy.yaml to your container registry. For a cloud cluster, connect the registry so the cluster can pull the image. section 7.12 section 6.15
- Run kubectl apply -f scripts/deploy.yaml. Check the result with kubectl get pods, kubectl get deployments, and kubectl get services; the single-replica example should have one application pod. section 6.11.5 section 6.8.5
- When testing is finished, run kubectl delete -f scripts/deploy.yaml and check that the objects created from the file are gone. section 6.11.7
Local and cloud configurations differ. The local example uses an image already available to the cluster; the Azure example names a registry image and uses IfNotPresent to pull it when needed. Its LoadBalancer Service provides an external IP for testing, but also exposes the microservice to attacks and abuse. Multiple replicas can provide redundancy and load balancing; this working configuration starts with one. section 6.11.4 section 6.4.3 section 6.8.3









