Kubernetes ingress - AKS

4/21/2020

I have followed the steps mentioned in this nginx for kubernetes, For installing this in azure i ran the following

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud/deploy.yaml

I opened that file and under the section # Source: ingress-nginx/templates/controller-deployment.yaml i could see the resources, is there a way to override this and set the cpu and memory limit for that ingress and also i would like to know whether everything in there is customisable.

-- doc_noob
azure-aks
kubernetes
nginx

2 Answers

4/21/2020

what the comment suggests ( download the file and manually override it or use helm chart ) or use kubectl edit deployment xxx and set those limits\requests.

-- 4c74356b41
Source: StackOverflow

4/21/2020

I would like to know whether everything in there is customizable.

Almost everything is customizable, but keep in mind that you must know exactly what are you changing, otherwise it can break your ingress.

Is there a way to override this and set the cpu and memory limit for that ingress?

Aside for download and editing the file before deploying it, Here are three ways you can customize it on the run:

  1. Kubectl Edit:

    • The edit command allows you to directly edit any API resource you can retrieve via the command line tools.
    • It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows.
    • You can edit multiple objects, although changes are applied one at a time. Example:
kubectl edit deployment ingress-nginx-controller -n ingress-nginx

This is the command that will open the deployment mentioned in the file. If you make an invalid change, it will not apply and will save to a temporary file, so use it with that in mind, if it's not applying, you changed something you shouldn't like the structure.

  1. Kubectl Patch using a yaml file:
    • Update field(s) of a resource using strategic merge patch, a JSON merge patch, or a JSON patch.
    • JSON and YAML formats are accepted.

Create a simple file called patch-nginx.yaml with the minimal following content (the parameter you wish to change and his structure):

spec:
  template:
    spec:
      containers:
        - name: controller
          resources:
            requests:
              cpu: 111m
              memory: 99Mi

The command structure is: kubectl patch <KIND> <OBJECT_NAME> -n <NAMESPACE> --patch "$(cat <FILE_TO_PATCH>)"

Here is a full example:

$ kubectl patch deployment ingress-nginx-controller -n ingress-nginx --patch "$(cat patch-nginx.yaml)" 
deployment.apps/ingress-nginx-controller patched

$ kubectl describe deployment ingress-nginx-controller -n ingress-nginx | grep cpu
      cpu:      111m
$ kubectl describe deployment ingress-nginx-controller -n ingress-nginx | grep memory
      memory:   99Mi
  1. Kubectl Patch with JSON format:
    • This is the one-liner version and it follows the same structure as the yaml version, but we will pass the parameter in a json structure instead:
$ kubectl patch deployment ingress-nginx-controller -n ingress-nginx --patch '{"spec":{"template":{"spec":{"containers":[{"name":"controller","resources":{"requests":{"cpu":"122m","memory":"88Mi"}}}]}}}}'
deployment.apps/ingress-nginx-controller patched

$ kubectl describe deployment ingress-nginx-controller -n ingress-nginx | grep cpu
      cpu:      122m
$ kubectl describe deployment ingress-nginx-controller -n ingress-nginx | grep memory
      memory:   88Mi

If you have any doubts, let me know in the comments.

-- willrof
Source: StackOverflow