Search⌘ K

Create a Service—The Declarative Way

Explore how to create a Kubernetes Service the declarative way using a YAML manifest file. Understand key components like metadata, labels, and spec details to deploy a LoadBalancer Service. Learn to apply these concepts practically by deploying and verifying the Service within your cluster for effective traffic routing.

We'll cover the following...

It’s time to do things the proper way — the Kubernetes way.

A Service manifest file

The following YAML is from the lb.yml file, and we’ll use it to deploy a LoadBalancer Service declaratively.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: svc-test
spec:
  replicas: 10
  selector:
    matchLabels:
      chapter: services
  template:
    metadata:
      labels:
        chapter: services
    spec:
      containers:
      - name: hello-ctr
        image: nigelpoulton/k8sbook:1.0
        ports:
        - containerPort: 8080
Playground

Let’s go through it. ...