Create Ingress EKS

October 06, 2023

ingress_logo

In this article, we'll guide you through the step-by-step process of setting up and configuring you application to expose it to the internet using NGINX Controller

You can find source code in our Github repo

Prerequisites:

  1. Kubernetes Cluster: You'll need a running Kubernetes cluster. If you don't have one, follow our guide on creating an EKS cluster using Terraform to set up a Kubernetes cluster on AWS Elastic Kubernetes Service (EKS)
  2. Kubectl: Ensure that you have kubectl installed on your local machine to interact with your Kubernetes cluster. You can install it following the instructions in the official Kubernetes documentation.
  3. NGINX Ingress Controller installed: please check our article here for detailed guide

Deploying test application for our ingress

In order to test our Ingress we would need to deploy test application so it can respond to our requests. To do so we would create test-app.yaml file :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpbin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: httpbin
      version: v1
  template:
    metadata:
      labels:
        app: httpbin
        version: v1
    spec:
      containers:
      - image: docker.io/kong/httpbin
        imagePullPolicy: IfNotPresent
        name: httpbin
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: httpbin
  labels:
    app: httpbin
    service: httpbin
spec:
  ports:
  - name: http
    port: 8000
    targetPort: 80
  selector:
    app: httpbin

Run the folliwong command:

kubectl apply -f <PATH_TO_YOUR_FILE>

Create Ingress

Since we alredy have our Service and Deployment we need to expose it. For that we would use Ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: httpbin
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: a37dedfa9d2e543b681d79cefd9bd01b-1181636763.us-east-1.elb.amazonaws.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: httpbin
            port:
              number: 8000

Please note that - host: field value should be your host name or DNS Name. Sometimes you would not have domain name configured yet. Your DNS name should be pointing to your load balancer(You can use Route 53 to create alias record). For this tutorial we used simplified example, using ELB/loadbalancer DNS Name for testing

Testing the Ingress

Copy EXTERNAL-IP Address to your clipboard and open it in a browser. You should see Connection is not secure message, since we didn't configure TLS Certificate yet. Just click to proceed anyway. Now you would see httpbin.org page, a service that we defined in our Deployment

Also you can use curl for testing the Ingress

curl -k <EXTERNAL-IP_Address>

or

curl --insecure <EXTERNAL-IP_Address>

You can find source code in our Github repo