Tuesday, 19 November 2024

How to disable Ingress in Kubernetes (K8s)

 Introduction

There are multiple ways you can disable Ingress in Kubernetes / K8s. Here are the 5 different ways you can directly or indirectly disable the Ingress



1. Deleting the Ingress Resource

If you need to completely remove ingress functionality from your Kubernetes cluster, the most straightforward approach is to delete the ingress resource. This stops all traffic from being routed through it.

Command

kubectl delete ingress <ingress-name> -n <namespace>


For example :

kubectl delete ingress my-ingress -n default


2. Scaling Down the Ingress Controller

If you only want to temporarily stop ingress traffic without removing anything permanently, you can scale down the ingress controller to zero replicas. This effectively halts ingress without deleting the controller.

    (i) First, identify the ingress controller deployment:


kubectl get deployments -n <controller-namespace>

    (ii) Then, scale the deployment down to zero replicas:


kubectl scale deployment <controller-deployment-name> --replicas=0 -n <controller-namespace>


    For example :

kubectl scale deployment <controller-deployment-name> --replicas=0 -n <controller-namespace>


3. Modifying Network Access

Another way to disable ingress traffic is by adjusting the network access or firewall settings at the external level. For example, you can modify the load balancer settings or block access via firewall rules to prevent any external traffic from reaching the ingress controller.


4. Editing the Ingress Configuration

If you want to disable certain routes or services but keep the ingress resource active, you can edit the configuration directly. Simply comment out or remove the paths you want to disable in the rules section of the ingress YAML file:

rules:
  - host: example.com
    http:
      paths:
        # - path: /old-path
        #   backend:
        #     service:
        #       name: old-service
        #       port:
        #         number: 80
        - path: /new-path
          backend:
            service:
              name: new-service
              port:
                number: 80


    Once you've updated the file, apply the changes:

kubectl apply -f <ingress-file>.yaml


5. Using Ingress Annotations

Some ingress controllers, like NGINX, allow you to control the availability of specific rules or the entire ingress resource using annotations. To disable an ingress resource entirely, you can add the following annotation:


metadata:
  annotations:
    nginx.ingress.kubernetes.io/enable: "false"


    Once you've updated the file, apply the changes:

kubectl apply -f <ingress-file>.yaml


Based on the scenario, we can choose one solution to disable ingress in Kubernetes.


No comments:

Post a Comment