Kubernetes 入口-AKS

Kubernetes ingress - AKS

我已按照此 nginx for kubernetes 中提到的步骤进行操作,为了在 azure 中安装此 运行 以下

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

我打开了那个文件,在 # Source: ingress-nginx/templates/controller-deployment.yaml 部分下我可以看到 resources,有没有办法覆盖它并设置 cpumemory 限制为此 ingress 而且我想知道里面的所有东西是否都是可定制的。

评论的建议(下载文件并手动覆盖它或使用 helm chart)或使用 kubectl edit deployment xxx 并设置那些 limits\requests.

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

几乎所有内容都是可自定义的,但请记住,您必须确切知道要更改的内容,否则可能会中断您的访问。

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

除了在部署前下载和编辑文件外,您还可以通过以下三种方式在 运行 上对其进行自定义:

  1. Kubectl Edit:

    • 编辑命令允许您直接编辑任何可以通过命令行工具检索的 API 资源。
    • 它将打开由您的 KUBE_EDITOR 或 EDITOR 环境变量定义的编辑器,或者退回到 'vi' for Linux 或 'notepad' for Windows.
    • 您可以编辑多个对象,但一次只能应用一个更改。 示例:
kubectl edit deployment ingress-nginx-controller -n ingress-nginx

这是将打开文件中提到的部署的命令。如果您进行了无效更改,它将不会应用并将保存到临时文件,因此请牢记这一点,如果它不适用,则您更改了一些您不应该喜欢的结构。

  1. Kubectl Patch 使用 yaml 文件
    • 使用战略合并补丁、JSON 合并补丁或 JSON 补丁更新资源字段。
    • JSON 和 YAML 格式被接受。

创建一个名为 patch-nginx.yaml 的简单文件,其中包含最少的以下内容(您要更改的参数及其结构):

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

命令结构为:kubectl patch <KIND> <OBJECT_NAME> -n <NAMESPACE> --patch "$(cat <FILE_TO_PATCH>)"

这是一个完整的例子:

$ 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:
    • 这是单行版本,它遵循与 yaml 版本相同的结构,但我们将在 json 结构中传递参数:
$ 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

如有任何疑问,请在评论中告诉我。