我遵循了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
,有没有一种方法可以覆盖它并为该cpu
设置memory
和ingress
限制,而且我想知道其中是否所有内容都是可定制的。
最佳答案
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?
除了在部署文件之前下载和编辑文件之外,还可以通过以下三种方式在运行时自定义文件:
示例:
kubectl edit deployment ingress-nginx-controller -n ingress-nginx
这是将打开文件中提到的部署的命令。如果您进行了无效的更改,则该更改将不适用并将保存到临时文件中,因此请牢记这一点,如果不进行更改,则应更改一些您不喜欢的结构。
使用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
$ 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
如果您有任何疑问,请在评论中告诉我。
关于nginx - Kubernetes入口-AKS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61339852/