Exposing BookNest

Exposing BookNest's API and Front End

The front end, Docker's Nginx 75 image, proxies /api/ to API_UPSTREAM. It gets a Deployment and a NodePort Service on 30080, which Multi-Node Cluster's kind 14,561 config maps to 127.0.0.1:33080:

k8s/web.yaml: the front end, published on NodePort 30080YAML
apiVersion: apps/v1
kind: Deployment
metadata: { name: web, labels: { app: booknest, tier: web } }
spec:
  replicas: 2
  selector: { matchLabels: { app: booknest, tier: web } }
  template:
    metadata: { labels: { app: booknest, tier: web } }
    spec:
      containers:
      - name: nginx
        image: localhost:33500/booknest-web:1.3
        env: [{ name: API_UPSTREAM, value: "api.booknest.svc.cluster.local:3000" }]
        ports: [{ name: http, containerPort: 80 }]
---
apiVersion: v1
kind: Service
metadata: { name: web, labels: { app: booknest, tier: web } }
spec:
  type: NodePort
  selector: { app: booknest, tier: web }
  ports: [{ name: http, port: 80, targetPort: http, nodePort: 30080 }]
Deploying the front end and calling it through the host portShell
kubectl delete pod client && kubectl delete service api-headless docs
kubectl apply -f k8s/web.yaml && kubectl rollout status deployment/web >/dev/null
kubectl get services
sleep 3; curl -s http://127.0.0.1:33080/api/books/3 | cut -c1-90
Output
pod "client" deleted from booknest namespace
service "api-headless" deleted from booknest namespace
service "docs" deleted from booknest namespace
deployment.apps/web created
service/web created
NAME   TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
api    ClusterIP   10.96.121.82   <none>        3000/TCP       40s
db     ClusterIP   10.96.28.125   <none>        5432/TCP       27m
web    NodePort    10.96.41.131   <none>        80:30080/TCP   2s
{"id":3,"title":"Salt and Saffron","author":"Priya Nair","genre":"Cooking","price":24,"rat

The request crossed every layer: host port, NodePort, a web Pod, CoreDNS 366,312 , the API's ClusterIP and a replica. With the image's Compose 514 default, API_UPSTREAM=api:3000, every /api/ call returned 502 Bad Gateway. In a Windows browser the page is at http://localhost:33080:

BookNest's front end served from the kind cluster through NodePort 30080 (headless Chrome on the Windows host)
BookNest's front end served from the kind cluster through NodePort 30080 (headless Chrome 1 on the Windows host)

Ingress and the Gateway API replaces the NodePort with host- and path-based routing through Ingress and the Gateway API.