25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Defining our K8s Service

February 28, 2021
Elliot Forbes

Elliot Forbes

Course Instructor

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

The final piece of the puzzle is to define a k8s service:

apiVersion: v1
kind: Service
metadata:
  name: comments-api
spec:
  type: NodePort
  selector:
    name: comments-api
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080

With this in place, we can now apply this service using the following command:

kubectl apply -f config/service.yml

We can then set up port-forwarding on our local machine to map localhost:8080 through to the kubernetes service running on port 8080:

kubectl port-forward service/comments-api 8080:8080