大网数据广告活动
服务器运维问答

How to see usage patterns of the `kubectl exec` command?

· 52CE 我爱测

In a kubernetes cluster I am trying to understand how the kubectl exec is used by the users. Users are exec'ing into which pods in which namespaces? What is the best way to discover that? I think the audit logs are a good startin…

问题原文

原帖链接 · Hakan Baba · CC BY-SA 4.0

In a kubernetes cluster I am trying to understand how the kubectl exec is used by the users. Users are exec'ing into which pods in which namespaces? What is the best way to discover that?

I think the audit logs are a good starting point but I am not sure whether I would find what I am looking for there.

已采纳解答

原帖链接 · mdaniel · CC BY-SA 4.0

Yes, the pod/exec request is tracked just like any other request in the audit log, and it even appears to track the command issued (although that won't be as helpful if the command is just sh or bash)

{
  "kind": "Event",
  "apiVersion": "audit.k8s.io/v1",
  "level": "Request",
  "auditID": "0f5bcb21-ef16-443e-bca2-1d26209207b9",
  "stage": "ResponseStarted",
  "requestURI": "/api/v1/namespaces/kube-system/pods/sample-647b485b68-4tc9h/exec?command=ps&command=auwx&container=sample&stderr=true&stdout=true",
  "verb": "create",
  "user": {
    "username": "kubernetes-admin",
    "groups": [
      "system:masters",
      "system:authenticated"
    ]
  },
  "sourceIPs": [
    "10.128.4.90"
  ],
  "userAgent": "kubectl/v1.19.2 (linux/amd64) kubernetes/f574309",
  "objectRef": {
    "resource": "pods",
    "namespace": "kube-system",
    "name": "sample-647b485b68-4tc9h",
    "apiVersion": "v1",
    "subresource": "exec"
  },
  "responseStatus": {
    "metadata": {},
    "code": 101
  },
  "requestReceivedTimestamp": "2020-10-06T16:06:48.205785Z",
  "stageTimestamp": "2020-10-06T16:06:48.258680Z",
  "annotations": {
    "authorization.k8s.io/decision": "allow",
    "authorization.k8s.io/reason": ""
  }
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-10-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。