skip to Main Content

I’m struggling with a very basic example of an Ingress service fronting an nginx pod. When ever I try to visit my example site I get this simple text output instead of the default nginx page:

404 page not found

Here is the deployment I’m working with:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 4
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
  namespace: default
spec:
  rules:
  - host: argo.corbe.net
    http:
      paths:
      - backend:
          serviceName: ningx
          servicePort: 80

k3s kubectl get pods -o wide:

NAME                              READY   STATUS    RESTARTS   AGE   IP           NODE    NOMINATED NODE   READINESS GATES
nginx-deployment-d6dcb985-942cz   1/1     Running   0          8h    10.42.0.17   k3s-1   <none>           <none>
nginx-deployment-d6dcb985-d7v69   1/1     Running   0          8h    10.42.0.18   k3s-1   <none>           <none>
nginx-deployment-d6dcb985-dqbn9   1/1     Running   0          8h    10.42.1.26   k3s-2   <none>           <none>
nginx-deployment-d6dcb985-vpf79   1/1     Running   0          8h    10.42.1.25   k3s-2   <none>           <none>

k3s kubectl -o wide get services:

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE   SELECTOR
kubernetes      ClusterIP   10.43.0.1       <none>        443/TCP   5d    <none>
nginx-service   ClusterIP   10.43.218.234   <none>        80/TCP    8h    app=nginx

k3s kubectl -o wide get ingress:

NAME            CLASS    HOSTS            ADDRESS          PORTS   AGE
nginx-ingress   <none>   argo.corbe.net   207.148.25.119   80      8h

k3s kubectl describe deployment nginx-deployment:

Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Mon, 22 Feb 2021 15:19:07 +0000
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision: 2
Selector:               app=nginx
Replicas:               4 desired | 4 updated | 4 total | 4 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx
    Port:         8080/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-7848d4b86f (4/4 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  2m43s  deployment-controller  Scaled up replica set nginx-deployment-7848d4b86f to 1
  Normal  ScalingReplicaSet  2m43s  deployment-controller  Scaled down replica set nginx-deployment-d6dcb985 to 3
  Normal  ScalingReplicaSet  2m43s  deployment-controller  Scaled up replica set nginx-deployment-7848d4b86f to 2
  Normal  ScalingReplicaSet  2m40s  deployment-controller  Scaled down replica set nginx-deployment-d6dcb985 to 2
  Normal  ScalingReplicaSet  2m40s  deployment-controller  Scaled up replica set nginx-deployment-7848d4b86f to 3
  Normal  ScalingReplicaSet  2m40s  deployment-controller  Scaled down replica set nginx-deployment-d6dcb985 to 1
  Normal  ScalingReplicaSet  2m40s  deployment-controller  Scaled up replica set nginx-deployment-7848d4b86f to 4
  Normal  ScalingReplicaSet  2m38s  deployment-controller  Scaled down replica set nginx-deployment-d6dcb985 to 0

2

Answers


  1. you are getting 404 which mean request is coming till nginx or ingress you are using

    there might be now issue with your ingress

    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    metadata:
      name: nginx-ingress
      namespace: default
    spec:
      rules:
      - host: argo.corbe.net
        http:
          paths:
          - backend:
              serviceName: ningx
              servicePort: 80
    

    check the service name you are using serviceName: ningx.

    it should be nginx-service ingress should be something like

    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    metadata:
      name: nginx-ingress
      namespace: default
    spec:
      rules:
      - host: argo.corbe.net
        http:
          paths:
          - backend:
              serviceName: nginx-service
              servicePort: 80
    

    whole flow will goes something like : DNS > ingress > service (nginx-service) > deployment (nginx-deployment) or pod replicas.

    Login or Signup to reply.
  2. nginx image listens for connection on port 80 by default.

    $ kubectl run --image nginx
    $ kubectl exec -it nginx -- bash
    root@nginx:/# apt update
        **output hidden**
    root@nginx:/# apt install iproute2
        **output hidden**
    root@nginx:/# ss -lunpt
    Netid     State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port                                     
    tcp       LISTEN     0          0                    0.0.0.0:80                0.0.0.0:*        users:(("nginx",pid=1,fd=7))    
    tcp       LISTEN     0          0                          *:80                      *:*        users:(("nginx",pid=1,fd=8))    
    

    Notice it’s port 80 that is open, not port 8080.
    This mean that your service is misconfigured because it forwards to port 8080.

    You should set target port to 80 like following.:

    apiVersion: v1
    kind: Service
    metadata:
      name: nginx-service
    spec:
      selector:
        app: nginx
      ports:
        - protocol: TCP
          port: 80
          targetPort: 80    # <- HERE
    

    Also notice the service name:

    kind: Service
    metadata:
      name: nginx-service
    

    And as a backed you put service of a different name:

    - backend:
        serviceName: ningx
    

    Change it to the actual name of a service, like below:

    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    metadata:
      name: nginx-ingress
      namespace: default
    spec:
      rules:
      - host: argo.corbe.net
        http:
          paths:
          - backend:
              serviceName: ningx-service
              servicePort: 80
    

    Apply the changes and it should work now.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search