对于docker容器,可以在run的时候,指定--sysctl 和对应的内核参数
那么,对于pod该如何进行修改?
接下来的内容,将会告诉你,如何进行修改
方法非常的简单......
通过initContainer
示例如下:
1、编辑deployment文件
kubectl edit deploy php-apache
2、增加initContainer
这里使用busybox这个工具镜像
172.20.58.152/middleware/busybox:1.36
可以下载busybox镜像,上传到本地的镜像仓库中,在image替换为自己的busybox就可以,具体的版本用最新的就可以了。
initContainers: - command: - sh - -c - | sysctl -w net.core.somaxconn=65535 sysctl -w net.ipv4.ip_local_port_range="1024 65535" sysctl -w net.ipv4.tcp_tw_reuse=1 sysctl -w fs.file-max=1048576 sysctl -w net.ipv4.tcp_keepalive_time=600 image: 172.20.58.152/middleware/busybox:1.36 imagePullPolicy: Always name: setsysctl resources: {} securityContext: privileged: true
位置如下:
保存,pod重启后,进入pod:
[root@nccztsjb-node-23 ~]# kubectl get po | grep php php-apache-5b8b8684b5-8gs8g 1/1 Running 0 8m13s php-apache-5b8b8684b5-977nf 1/1 Running 0 8m16s php-apache-5b8b8684b5-9g6d4 1/1 Running 0 8m16s php-apache-5b8b8684b5-bfxmh 1/1 Running 0 8m13s php-apache-5b8b8684b5-mn9t8 1/1 Running 0 8m16s php-apache-5b8b8684b5-nmt8t 1/1 Running 0 8m13s php-apache-5b8b8684b5-q978d 1/1 Running 0 8m10s [root@nccztsjb-node-23 ~]# kubectl exec -it php-apache-5b8b8684b5-8gs8g -c php-apache -- bash root@php-apache-5b8b8684b5-8gs8g:/var/www/html# sysctl -a | grep net.ipv4.tcp_keepalive_time net.ipv4.tcp_keepalive_time = 600 sysctl: reading key "net.ipv6.conf.all.stable_secret" sysctl: reading key "net.ipv6.conf.default.stable_secret" sysctl: reading key "net.ipv6.conf.eth0.stable_secret" sysctl: reading key "net.ipv6.conf.lo.stable_secret" root@php-apache-5b8b8684b5-8gs8g:/var/www/html#
net.ipv4.tcp_keepalive_time = 600 这个内核参数,已经成功修改了,不是默认的7200了。
标签:5b8b8684b5,php,sysctl,Running,内核,apache,pod,k8s,net From: https://www.cnblogs.com/chuanzhang053/p/17435306.html