kubernetes is not able forward port

11/16/2019

I am new to kubernetes, I have the deployment.yaml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: pdemo
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      papi: web
  template:
    metadata:
      labels:
        papi: web
    spec:
      containers:
      - name: pdemodemo-site
        image:pdemoapi:4.0
        ports:
        - containerPort: 443
---
apiVersion: v1
kind: Service
metadata:
  name: pdemo-entrypoint
  namespace: default
spec:
  type: LoadBalancer
  selector:
    bb: web
  ports:
  - port: 44328
    targetPort: 443

I applied this deployment.yaml file and request for the kubectl get service

NAME                          TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)           AGE
kubernetes                    ClusterIP      10.96.0.1       <none>        443/TCP           19h
pdemo-entrypoint              LoadBalancer   10.111.16.228   localhost     44328:31656/TCP   60m

Then i did kubectl port-forward service/pdemo-entrypoint --address "localhost" 31656:44328

which resulted

Forwarding from 127.0.0.1:31656 -> 443
Forwarding from [::1]:31656 -> 443
Handling connection for 31656
Handling connection for 31656

Then when i tried to request from the browser , I get

E1116 09:35:14.268697    2692 portforward.go:400] an error occurred forwarding 31656 -> 443: error forwarding port 443 to pod 54c1096fd343af2d0bc356c3ee52a54ac0db586e0f978fd3a0062278fe7aeb98, uid : exit status 1: 2019/11/16 14:35:14 socat[33825] E connect(21, AF=2 127.0.0.1:443, 16): Connection refused

Here is my docker image file

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine3.8 AS base
WORKDIR /app
EXPOSE 443
COPY ./xyz/publish .
ENV ASPNETCORE_URLS=https://+:443;http://+80
ENTRYPOINT ["dotnet","xyz.dll"]

FYI: I am using docker-desktop

-- sumanth d
docker
google-kubernetes-engine
kubernetes
kubernetes-pod

1 Answer

11/16/2019

If you type in browser localhost:31656, it doesn't mean that traffic routed to https, by default browser transform that to http://localhost:31656, in other words, you routing unencrypted traffic to the encrypted endpoint.

Try to specify that you want https://, by typing https://localhost:31656

curl -LO https://localhost:31656
-- Oleg Butuzov
Source: StackOverflow