【问题标题】:Create one liner (Imperative way) command in kubernetes在 kubernetes 中创建一个线性(命令式)命令
【发布时间】:2021-07-02 11:50:43
【问题描述】:

在 kubernetes 中创建一个线性(命令式)命令

kubectl run test --image=ubuntu:latest --limits="cpu=200m,memory=512Mi" --requests="cpu=200m,memory=512Mi" --privileged=false

而且我还需要在一个班轮中设置securityContext,可以吗?基本上我需要以securityContext/runAsUser 而不是root 帐户运行容器。

是的,声明式有效,但我正在寻找一种命令式的方式。

【问题讨论】:

标签: kubernetes kubectl


【解决方案1】:

将此答案发布为社区 wiki,以突出显示该解决方案已发布在 cmets 中的事实(指向另一个答案的链接):

您好,请查看此答案:stackoverflow.com/a/37621761/5747959 您可以使用 --overrides – CLNRMN 2 天前解决此问题

随意编辑/扩展。


引用$ kubectl run --help

  --overrides='': An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field.

按照--overrides 示例,其中包含附加字段并且更具体地针对此特定问题(securityContext 明智):

kubectl run -it ubuntu --rm --overrides='
{
  "apiVersion": "v1",
  "spec": {
    "securityContext": {
      "runAsNonRoot": true,
      "runAsUser": 1000,
      "runAsGroup": 1000,
      "fsGroup": 1000
    },
    "containers": [
      {
        "name": "ubuntu",
        "image": "ubuntu",
        "stdin": true,
        "stdinOnce": true,
        "tty": true,
        "securityContext": {
          "allowPrivilegeEscalation": false
        }
      }
    ]
  }
}
' --image=ubuntu --restart=Never -- bash

通过上述覆盖,您将使用securityContext 来限制您的工作量。

旁注!

  • 上面的示例特定于运行 Pod,您将执行到 (bash)
  • --overrides 将覆盖它之外的其他指定参数(例如:image

其他资源:

【讨论】:

    猜你喜欢
    • 2020-02-21
    • 1970-01-01
    • 2013-09-22
    • 2020-10-31
    • 2015-10-26
    • 2020-10-15
    • 2020-05-09
    • 2012-01-30
    • 1970-01-01
    相关资源
    最近更新 更多