nginx-ingress not working on my IP adress

2/19/2022

I am trying to run a microservice from my docker image, the service(html) on my docker image (my-account/my-service), I have nginx running on port 80. I want and I want to that service run on HTTP://my-public-ip/login

I got forbidden after applying, Im not sure if the issue from ingress side or I missed something

kubectl -n my-ns apply -f deploy.yaml -f service.yml -f ingress.yml

curl http://xx.xx.xx.xx/login (xx.xx.xx.xx is my public ip)

<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.21.6</center>
</body>
</html>

here are my files

service.yml

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: ClusterIP
  selector:
    app: my-service
  ports:
    - port: 80
      targetPort: 80

deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-service
  labels:
    app: my-service
    type: api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-service
  template:
    metadata:
      labels:
        app: my-service
    spec:
      containers:
      - name: my-service
        image: my-account/my-service
        ports:
        - containerPort: 80

ingress.yml

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-service
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
   - http:
      paths:
      - path: /login
        pathType: Prefix
        backend:
          service:
            name: my-service
            port:
              number: 80
  ingressClassName: my-service
  defaultBackend:
    service:
      name: my-service
      port:
        number: 80

---
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  name: my-service
  labels:
    app.kubernetes.io/component: controller
  name: my-service
  annotations:
    ingressclass.kubernetes.io/is-default-class: "true"
spec:
  controller: k8s.io/ingress-nginx

kubectl get ingress -n my-ns

NAME                     CLASS   HOSTS   ADDRESS   PORTS   AGE
my-service               nginx   *                 80      23s

kubectl get pods -n my-ns

my-service-5468fdfb6d-d2mp7   1/1     Running   0          4m5s

kubectl get svc -n my-ns
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
my-service       ClusterIP   10.102.13.118   <none>        80/TCP    33m

kubectl get deployments -n my-ns

my-service       1/1     1            1           33m

kubectl describe ingress my-service -n dev

Labels:           <none>
Namespace:        my-ns
Address:
Default backend:  my-service:80 (172.17.0.5:80)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /login   my-service:80 (172.17.0.5:80)
Annotations:  nginx.ingress.kubernetes.io/rewrite-target: /
Events:       <none>
-- Sara
docker
kubernetes
nginx
nginx-ingress

0 Answers