K8S configures the security context securityContext for Pod or container to solve the problem of Docker container limiting the number of file handles


One, the problem

I need to set the maximum number of file handles in the container to 204800, but it is rejected. This is caused by Docker's own security mechanism

Talking about Docker security support

Insert picture description here

Two, the solution

方法一:简单粗暴

Set the container to privileged mode, but the security is not high

Add the following two lines to the yaml file

securityContext:
      privileged: true

Insert picture description here

kubectl apply -f pod-01.yaml			#发现有如下报错

Insert picture description here
Need to delete the previous Pod, and then execute kubectl apply

kubectl delete -f pod-01.yaml
kubectl apply -f pod-01.yaml

Insert picture description here
No error is reported this time, enter the container

kubectl exec -it pod-01 bash
ulimit -n 204800

Set successfully
Insert picture description here

方法二:温柔可佳

Add the capabilities in the CAP_SYS_RESOURCEcapabilities to the container , with high security
Insert picture description here

Capability introduction click here

securityContext:
      capabilities:
        add: ["SYS_RESOURCE"]

Insert picture description here

Guess you like

Origin blog.csdn.net/anqixiang/article/details/108546101