Ravindra BagaleCourses & study guides

Chapter 15: Kubernetes Introduction

15.5 Manifest sketch — Deployment + Service for badge API

Replace the image with one you built/pushed in earlier chapters (GHCR/Docker Hub). Prefer an immutable tag (sha-… or version), not only latest.

# badge-deploy.yaml — learning sketch
apiVersion: apps/v1
kind: Deployment
metadata:
  name: badge-api
  namespace: badge-api
  labels:
    app: badge-api
spec:
  replicas: 2
  selector:
    matchLabels:
      app: badge-api
  template:
    metadata:
      labels:
        app: badge-api
    spec:
      containers:
        - name: api
          image: ghcr.io/example/badge-api:sha-a3f2c1 # replace with YOUR tag
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: badge-api
  namespace: badge-api
spec:
  selector:
    app: badge-api
  type: ClusterIP
  ports:
    - name: http
      port: 80
      targetPort: 8080

Namespace first:

apiVersion: v1
kind: Namespace
metadata:
  name: badge-api
kubectl apply -f namespace.yaml
kubectl apply -f badge-deploy.yaml
kubectl get pods,svc -n badge-api

Ports are published ports: containerPort: 8080 is the counter inside the Pod building; Service port: 80 is the directory number other Pods dial; targetPort maps to the container counter. Same analogy as Docker -p — logical numbers, not CPU pins.