Docs
Project ServicesFAQ

K8s questions

How to Set Up Ingress in Kubernetes

Kubernetes as a project supports and maintains AWS, GCE, and nginx ingress controllers. There are third-party projects that provide ingress functionality, but we recommend using the most universal and officially supported Nginx-ingress to easilay route HTTP and HTTPS traffic entering the cluster through a single entry point to different services inside the cluster, as the various Ingress controllers operate slightly differently.

You can find the full official documentation on how to deploy Nginx here Installation Guide - Ingress-Nginx Controller

Guide how to Set Up Ingress in Kubernetes

On most Kubernetes clusters, the ingress controller will work without requiring any extra configuration. You need to create an Ingress Controller (Nginx in our example), define Ingress Resources, and configure your DNS. This is an introductory short installation Nginx-Controller guide. The full installation version with all conditions can be found here.

There are a few ways to install a Nginx Ingress Controller on your managed Kubernetes:

  1. With Helm (package manager), using the project repository chart. The controller will be installed in the ingress-nginx namespace. If the controller is already installed, it will upgrade it. Then you can get a full list of values that you can set. The default set of helm values is not configured for installation on any infra provider. The annotations that are applicable to the cloud provider must be customized by the users.
helm upgrade --install ingress-nginx ingress-nginx \
  --repo https://kubernetes.github.io/ingress-nginx \
  --namespace ingress-nginx --create-namespace
helm show values ingress-nginx --repo https://kubernetes.github.io/ingress-nginx
  1. With kubectl apply, using YAML manifests. Here is an example with the more stable version for now - {controller-v1.10.1}. Notice - it can be changed. If you prefer the newest one, use the command from the paragraph below.
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.10.1/deploy/static/provider/cloud/deploy.yaml --kubeconfig cluster.cfg
  1. With kubectl apply, using YAML manifests. Here is an example with the latest version ({main} branch)
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml --kubeconfig cluster.cfg

To test the Nginx, you can deploy a simple application along with a Service with kubectl apply

  1. Deploy a test application
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: gcr.io/google-samples/hello-app:1.0
        ports:
        - containerPort: 8080
  1. Create a Service:
apiVersion: v1
kind: Service
metadata:
  name: hello-world
spec:
  selector:
    app: hello-world
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  1. Apply these configurations:
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

Define how requests should be routed to the Services within your cluster:

  1. Create a Resource
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-world-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx-example
  rules:
  - host: hello-world.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: hello-world
            port:
              number: 80
  1. Apply the Resource
kubectl apply -f ingress.yaml

Configure DNS:

  1. Point your domain (e.g., hello-world.example.com) to the external IP of your Ingress Controller. You can find the external IP using:
kubectl get services -o wide -w --namespace ingress-nginx
  1. Update your DNS settings to map your domain to this external IP

Notice that Ingress primarily handles HTTP and HTTPS traffic. For other protocols (e.g., TCP, UDP), you would need a different type of resource, such as a LoadBalancer or a NodePort service.

Limitations of NGINX:

  • Configuring NGINX requires learning its unique syntax
  • In the free version, you can't easily add new features without rebuilding it. Some powerful features are only available in the paid version, NGINX Plus.
  • May struggle with CPU-intensive tasks
  • Compared to some other servers, NGINX has fewer built-in tools for managing complex applications
  • Requires third-party modules for some protocols
  • Getting WebSocket connections to work can be difficult
  • Basic Rate Limiting and DDoS Protection - for more advanced protection, you might need other tools.

Official links you may need:

  1. https://spacelift.io/blog/kubernetes-ingress
  2. https://kubernetes.io/docs/concepts/services-networking/ingress/
  3. https://kubernetes.github.io/ingress-nginx/deploy/#quick-start
  4. https://helm.sh/
How is this guide?

Last updated on 10 Jun 2024

On this page