Docker for mac 80 port is not useful with k8s + ingress, how can I fixed them?

5/9/2019

I used this config file to deploy a app , but I can't visit the url(I had add this domain to my /etc/hosts): http://gogs.app, and it has a response with the 307 status of https://gogs.app

I am using docker for mac 18.09.2 And k8s is installed by docker for mac.

Problem: I used this config file to deploy a app , but I can't visit the url(I had add this domain to my /etc/hosts): http://gogs.app, and it has a response with the 307 status of https://gogs.app

gogs-k8s  kubectl get pods                  
NAME                    READY     STATUS    RESTARTS   AGE
gogs-64cbd8c6f7-9qjbh   1/1       Running   0          32m
gogs-64cbd8c6f7-prcnf   1/1       Running   0          32m
gogs-64cbd8c6f7-rgcpn   1/1       Running   0          32m


gogs-k8s  kubectl get svc -n ingress-nginx 
NAME            TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx   LoadBalancer   10.110.146.125   localhost     80:31255/TCP,443:30359/TCP   10d


gogs-k8s  kubectl get svc                 
NAME            TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                       AGE
gogs-services   LoadBalancer   10.109.151.183   <pending>     80:31053/TCP,2222:30591/TCP   36m
kubernetes      ClusterIP      10.96.0.1        <none>        443/TCP                       10d

this is my gogs.yaml:

apiVersion: apps/v1
kind: Deployment 
metadata:
  name: gogs
spec:
  replicas: 3
  selector:
    matchLabels:
      app: gogs
  template:
    metadata:
      labels:
        app: gogs
    spec:
      containers:
        - name: gogs
          image: gogs/gogs:latest
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              memory: "200Mi"
              cpu: "500m"
          ports:
          - containerPort: 3000
            name: http
          - containerPort: 22
            name: ssh
          volumeMounts:
            - mountPath: /data
              name: gogs-repo
      volumes:
        - name: gogs-repo
          emptyDir: {}
---
apiVersion: v1
kind: Service 
metadata:
  labels:
    app: gogs
  name: gogs-services
spec:
  ports:
    - name: http
      port: 80
      targetPort: 3000
    - name: ssh
      port: 2222
      targetPort: 22
  selector:
    app: gogs
  type: LoadBalancer

--- 
apiVersion: extensions/v1beta1
kind: Ingress
metadata: 
  name: gogs
spec:
  rules:
    - host: gogs.app
      http:
        paths:
        - path: /
          backend:
            serviceName: gogs
            servicePort: 80

visit the url: http://gogs.app correct.

--
kubernetes
kubernetes-ingress

2 Answers

5/9/2019

If you don't want redirect to HTTPS then try using this manifest for ingress resource:

apiVersion: extensions/v1beta1
kind: Ingress
metadata: 
  name: gogs
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
    - host: gogs.app
      http:
        paths:
        - path: /
          backend:
            serviceName: gogs
            servicePort: 80
-- Vasily Angapov
Source: StackOverflow

5/9/2019

Since you deployed your k8s with Docker for Mac, I am assuming you are attempting to get your application working on a local machine. The problem is that you have defined host: gogs.app in your nginx ingress. You should change your ingress definition to:

apiVersion: extensions/v1beta1
kind: Ingress
metadata: 
  name: gogs
spec:
  rules:
    - host: localhost
      http:
        paths:
        - path: /
          backend:
            serviceName: gogs
            servicePort: 80

With Docker for Mac, it seems like your ingress-nginx is exposed externally on the localhost interface; thus it would not allow access externally. If you wish to use your domain name, consider deploying this in a cloud environment with static public IP addressing, and create the appropriate DNS records for it.

-- Frank Yucheng Gu
Source: StackOverflow