Score:0

Kubernetes Ingress not properly routing traffic

gb flag

I am trying to host a simple website using Kubernetes. I am trying to use a K8s deployment, service and an ingress to route the traffic from the external into the application running inside the pod.

The below is my YAML configuration file.

--- 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: trojanwall-deployment
  namespace: dev
  labels:
    app: trojanwall
spec:
  replicas: 1
  selector:
    matchLabels:
      app: trojanwall
  template:
    metadata:
      labels:
        app: trojanwall
    spec:
      containers:
      - name: trojanwall
        image: arbabu/trojan-wall:v1
        ports:
        - containerPort: 80 
--- 
apiVersion: v1
kind: Service
metadata:
  name: trojanwall-service
  namespace: dev
spec:
selector:
  app: trojanwall
ports:
- name: http
  protocol: TCP
  port: 3000
  targetPort: 80
type: ClusterIP 

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: trojanwall-ingress
  namespace: dev
spec:
  rules:
  - host: "ec2-3-96-217-161.compute-1.amazonaws.com"
    http:
      paths:
      - path: "/trojanwall"
        pathType: Prefix
        backend:
          service:
            name: trojanwall-service
            port:
              number: 3000

The following is the resource status.

enter image description here

The expectation is that, when I run something like 'http://ec2-3-96-217-161.compute-1.amazonaws.com/trojanwall', I should be able to access my website. However, I am getting the following.

enter image description here

Does anyone know how to configure the ingress traffic properly?

Score:1
hu flag

You need a loadbalancer, that is tipically provided by your cloud provider (which from that host name I guess it's AWS) which is very likely missing because you are also missing

ingressClassName: nginx

in spec section in your yaml file. This way the cloud load balancer can update the LoadBalancer ip address in the status section of nginx-ingress objects wich belong to that class.

The whole mechanis is in charge by the CCM (cloud controller manager), the k8s component which provides cloud specific features such as routing and service management (https://kubernetes.io/docs/concepts/architecture/cloud-controller/#service-controller)

When you have your ingress binded correctly it will show something like this:

$ kubectl get ingress
NAME        CLASS   HOSTS           ADDRESS       PORTS     AGE   
myingress   nginx   myhostname.my   10.11.12.13   80, 443   6d9h

Here is (part of) my ingress manifest, for reference:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod   
  name: myingress
  namespace: myns
spec:
  ingressClassName: nginx
  rules:
  - host: myhostname.my
    http:
      paths:
      - backend:
          service:
            name: myservice
            port:
              number: 8080
        path: /
        pathType: Prefix
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.