Running Spring Boot on Port 80 with Azure Kubernetes

12/19/2018

Given a Spring Boot application with docker-compose.yaml:

version: '3'
services:
  my-ws:
  build: .
  image: my-ws
   container_name: my-ws
   ports:
        - "8080:8080"

And kubernetes manifest:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: my-ws
spec:
  replicas: 3
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5
  template:
    metadata:
      labels:
        app: my-ws
    spec:
      containers:
      - name: my-ws
        image: myacr.azurecr.io/my-ws:v1
        ports:
        - containerPort: 8080
        resources:
          requests:
            cpu: 250m
          limits:
            cpu: 500m
---
apiVersion: v1
kind: Service
metadata:
  name: my-ws
spec:
  loadBalancerIP: <redacted>
  type: LoadBalancer
  ports:
    - port: 8080
  selector:
    app: my-ws

We can successfully deploy on Azure Kubernetes Service and the application responds on port 8080. We would like to have it respond on port 80. We have tried changing docker-compose.yaml ports to:

ports:
     - 80:80

and the manifest:

- containerPort: 80
...
-port: 80

and redeploying. The deployment succeeds, but the app is not available on either 8080 or 80.

-- Paul Croarkin
azure
azure-aks
azure-kubernetes
docker
kubernetes

1 Answer

12/19/2018

you need to map service port 80 to container port 8080, thats the easiest solution (and least disruptive):

---
apiVersion: v1
kind: Service
metadata:
  name: my-ws
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: my-ws

ps. leave everything else as it was before changes

-- 4c74356b41
Source: StackOverflow