DevOps Bootcamp · Lesson

Adding a Service Template

Exposing the workload through a templated Service.

Lesson 3 of 413 steps

Adding a Service Template is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

Why You Need a Service

Pods get new IPs constantly. A Service gives your workload one stable address so other things can reach it reliably.

A Second Template File

Add templates/service.yaml next to your deployment template. Helm renders every file in templates, so both ship together.

The Service Skeleton

A Service starts like any manifest: apiVersion, kind: Service, and metadata. The release name keeps it tied to this install.

apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}

The Selector Links Pods

A Service finds its pods through a selector. It must match the labels on your Deployment's pods, or no traffic flows.

spec:
  selector:
    app: {{ .Release.Name }}

Choose the Service Type

Parameterize type so users pick ClusterIP, NodePort, or LoadBalancer. ClusterIP is the safe in-cluster default.

type: {{ .Values.service.type }}

Default the Type in values

Give service.type a default so a plain install just works. Group service settings under one key to stay tidy.

# values.yaml
service:
  type: ClusterIP
  port: 80

Map the Port

The port is what clients connect to on the Service. Wire it to values so each install can expose a different port.

ports:
  - port: {{ .Values.service.port }}

Point at the Container Port

The targetPort is the port your container listens on. nginx serves on 80, so traffic on the Service forwards there.

ports:
  - port: {{ .Values.service.port }}
    targetPort: 80

Declare the Container Port

For clarity, list the port your pod opens in the Deployment's containerPort. It documents intent and aids tooling.

ports:
  - containerPort: 80

The Complete Service Spec

Put it together: a templated Service whose selector matches your pods and whose port and type come from values.

spec:
  type: {{ .Values.service.type }}
  selector:
    app: {{ .Release.Name }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: 80

Render Both Templates

Run helm template and confirm Helm emits two documents separated by ---: your Deployment and your new Service.

helm template web .

Quick Check

A Service sends no traffic to your pods. What is the most likely cause?

Recap: Exposing the App

You added a Service template: selector matches the pods, type and port come from values, and targetPort hits the container. 🚀

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “Adding a Service Template” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Adding a Service Template”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

What will I learn in “Adding a Service Template”?

Exposing the workload through a templated Service. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Adding a Service Template” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. A Minimal Deployment Template
  2. Parameterizing the Container Image
  3. Adding a Service Template
  4. Installing and Iterating Your Chart
← Back to DevOps Bootcamp