🚀 Get 25% off access to all my premium courses - use discount code FUNCMAIN at checkout - view the pricing page now!

Video:

Defining our K8s Service

February 28, 2021

Course Instructor: Elliot Forbes

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