Lesson 08 Services & Networking
Theme:

Homework

Three tasks that extend the lab exercises into production-grade Service patterns.

Complete all three lab exercises before starting the homework. These tasks build on the chart you created during the lab.

Task 1 — Dual-Service Chart: Public + Internal

Objective

Create a chart that deploys two Services for the same application: a public-facing LoadBalancer and an internal ClusterIP for health checks and metrics.

Instructions

  1. Add a second values block called internalService in values.yaml:
    service:
      type: LoadBalancer
      port: 443
      targetPort: 8443
      externalTrafficPolicy: Local
      annotations:
        service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
    
    internalService:
      enabled: true
      port: 9090
      targetPort: 9090
  2. Create templates/internal-service.yaml that renders a ClusterIP Service only when internalService.enabled is true
  3. The internal Service must use the same selector labels as the primary Service
  4. Name the internal Service with a -internal suffix
  5. Verify with helm template that both Services render correctly
  6. Install the chart and confirm both Services appear in kubectl get svc
  7. Verify that a test Pod can reach both endpoints

Deliverable

The complete templates/internal-service.yaml and updated values.yaml. Output of helm template showing both Services.

✓ Self-check: Two Services appear. The public Service has type LoadBalancer. The internal Service has type ClusterIP. Setting internalService.enabled=false removes the internal Service entirely.

Task 2 — ExternalName Service for an External Database

Objective

Add a templated ExternalName Service so applications can reference an external database by a stable in-cluster DNS name.

Instructions

  1. Add the following to values.yaml:
    externalDB:
      enabled: false
      name: app-database
      host: prod-db.c9abcdef.us-east-1.rds.amazonaws.com
  2. Create templates/external-db-service.yaml:
    • Kind: Service with type: ExternalName
    • externalName set from .Values.externalDB.host
    • No selector, no ports
    • Only renders when externalDB.enabled is true
  3. Verify the template renders correctly:
    helm template . --set externalDB.enabled=true | grep -A 10 "external"
  4. Install and verify DNS resolution:
    kubectl run dns-test --image=busybox:1.36 --rm -it --restart=Never -- \
      nslookup app-database.default.svc.cluster.local
  5. The DNS lookup should return a CNAME pointing to the RDS hostname

Deliverable

The complete templates/external-db-service.yaml template and updated values.yaml. Output of the DNS lookup confirming the CNAME.

✓ Self-check: The ExternalName Service renders only when enabled. nslookup returns the CNAME record. No selector or ports appear in the rendered YAML.

Task 3 — Conditional Headless Service Toggle

Objective

Refactor the headless Service template so it can optionally replace the primary Service (not just supplement it) and expose configurable multi-port definitions.

Instructions

  1. Update values.yaml:
    headless:
      enabled: false
      standalone: false    # if true, skip the primary Service
      ports:
        - name: gossip
          port: 7946
          targetPort: 7946
        - name: client
          port: 9042
          targetPort: 9042
  2. Update templates/service.yaml to skip rendering when headless.standalone is true:
    {{- if not (and .Values.headless.enabled .Values.headless.standalone) }}
  3. Update templates/headless-service.yaml to iterate over .Values.headless.ports instead of using the primary Service ports
  4. Verify all four scenarios with helm template:
    • headless.enabled=false — only primary Service renders
    • headless.enabled=true, standalone=false — both Services render
    • headless.enabled=true, standalone=true — only headless Service renders
    • Headless Service ports use the headless.ports array, not the primary service.ports

Deliverable

Updated templates/service.yaml, templates/headless-service.yaml, and values.yaml. Output of helm template for all four scenarios.

✓ Self-check: Each scenario produces the correct combination of Services. The headless Service ports match the headless.ports values. No rendering errors occur in any scenario.

Grading Rubric

CriterionPointsDescription
Task 1: Dual-Service35Both Services render with correct types, selectors, and conditional logic
Task 2: ExternalName25ExternalName Service renders correctly, DNS resolves the CNAME, conditional toggle works
Task 3: Headless toggle30All four scenarios produce correct output, ports are independently configurable
Code quality10Consistent naming, proper use of helpers, clean YAML output with no extra whitespace

Submission Checklist