Deploying Applications with Kubernetes

Once we have our application code built into a Docker image, we just have to configure a Kubernetes deployment manifest – something along the lines of:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: author
  labels:
    app: author
spec:
  selector:
    matchLabels:
      app: author
  template:
    metadata:
      labels:
        app: author
    spec:
      containers:
      - name: author
        image: author-service:latest
        imagePullPolicy: IfNotPresent

All we need to do now is deploy the application:

kubectl apply -f deployment.yaml

We can check on the status of the deployment by running by running the following command:

kubectl get pods

NAME                      READY   STATUS    RESTARTS   AGE
author-66f569d7f4-58h2d   1/1     Running   0          4m3s

Once we see that the application is now running, we can port forward into one of the pods in order for us to interact with it:

kubectl port-forward author-66f569d7f4-58h2d 5000

Forwarding from 127.0.0.1:5000 -> 5000
Forwarding from [::1]:5000 -> 5000

Finally, we just need to curl the endpoint and we get a successful response:

curl http://localhost:5000/authors

{"authors":[{"id":1,"name":"Kurt Vonnegut"},{"id":2,"name":"Edgar Allan Poe"}]}