searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

通过特权容器配置内核参数

2024-05-09 16:22:45
9
0

前提条件

开通特权容器需要通过命令行模式连接到目标集群,所以需要先保存集群kubeconfig,并且配置好kubectl环境。

修改主机的内核配置可能会对系统的稳定性和安全性产生影响,因此在进行这些操作时请谨慎考虑,并确保您具备足够的了解和经验。

后台操作流程

编写应用yaml,创建特权容器,示例如下:

kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: daemonset-test
  labels:
    name: daemonset-test
spec:
  selector:
    matchLabels:
      name: daemonset-test
  template:
    metadata:
      labels:
        name: daemonset-test
    spec:    
      hostNetwork: true
      containers:
      - name: daemonset-test
        image: nginx:alpine
        command:
        - "/bin/sh"
        args:
        - "-c"
        - while :; do  time=$(date);done
        imagePullPolicy: IfNotPresent
        lifecycle:
          postStart:
            exec:
              command:
              - sysctl
              - "-w"
              - net.ipv4.tcp_tw_reuse=1
        securityContext:
          privileged: true
      imagePullSecrets:
      - name: default-secret

spec.spec.containers.lifecycle 字段是指容器启动后执行设置的命令;

spec.spec.containers.securityContext.privileged: true  字段是指开启特权容器。

使用以上yaml文件创建特权容器:kubectl apply -f daemonset-test.yaml

执行后查看是否容器启动成功:kubectl get daemonset

当看到READY数量跟节点数量相同时,说明已经全部创建成功,则可以在当前主机执行kubectl get po |grep daemonset-test或者docker ps |grep daemonset-test查找对应容器。

找到对应容器id后,可以通过命令 docker exec -it 356d0e5a831c /bin/sh 或 kubectl exec -it podname -- bash 进入容器内部,然后执行命令sysctl -a |grep net.ipv4.tcp_tw_reuse查看对应的内容是否有修改命令行终端确认修改系统参数成功。

当输出结果与我们配置结果一致时说明系统参数修改成功。

0条评论
0 / 1000
l****n
2文章数
0粉丝数
l****n
2 文章 | 0 粉丝
l****n
2文章数
0粉丝数
l****n
2 文章 | 0 粉丝
原创

通过特权容器配置内核参数

2024-05-09 16:22:45
9
0

前提条件

开通特权容器需要通过命令行模式连接到目标集群,所以需要先保存集群kubeconfig,并且配置好kubectl环境。

修改主机的内核配置可能会对系统的稳定性和安全性产生影响,因此在进行这些操作时请谨慎考虑,并确保您具备足够的了解和经验。

后台操作流程

编写应用yaml,创建特权容器,示例如下:

kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: daemonset-test
  labels:
    name: daemonset-test
spec:
  selector:
    matchLabels:
      name: daemonset-test
  template:
    metadata:
      labels:
        name: daemonset-test
    spec:    
      hostNetwork: true
      containers:
      - name: daemonset-test
        image: nginx:alpine
        command:
        - "/bin/sh"
        args:
        - "-c"
        - while :; do  time=$(date);done
        imagePullPolicy: IfNotPresent
        lifecycle:
          postStart:
            exec:
              command:
              - sysctl
              - "-w"
              - net.ipv4.tcp_tw_reuse=1
        securityContext:
          privileged: true
      imagePullSecrets:
      - name: default-secret

spec.spec.containers.lifecycle 字段是指容器启动后执行设置的命令;

spec.spec.containers.securityContext.privileged: true  字段是指开启特权容器。

使用以上yaml文件创建特权容器:kubectl apply -f daemonset-test.yaml

执行后查看是否容器启动成功:kubectl get daemonset

当看到READY数量跟节点数量相同时,说明已经全部创建成功,则可以在当前主机执行kubectl get po |grep daemonset-test或者docker ps |grep daemonset-test查找对应容器。

找到对应容器id后,可以通过命令 docker exec -it 356d0e5a831c /bin/sh 或 kubectl exec -it podname -- bash 进入容器内部,然后执行命令sysctl -a |grep net.ipv4.tcp_tw_reuse查看对应的内容是否有修改命令行终端确认修改系统参数成功。

当输出结果与我们配置结果一致时说明系统参数修改成功。

文章来自个人专栏
文章 | 订阅
0条评论
0 / 1000
请输入你的评论
0
0