简体   繁体   English

如何查看 kubernetes 集群的 kubectl 执行历史?

[英]How to check kubectl execution history of a kubernetes cluster?

Suppose I have a Kubernetes cluster, devops manages the cluster using kubectl.假设我有一个 Kubernetes 集群,devops 使用 kubectl 管理集群。 How can I track the kubectl execution on the cluster to monitor if there is any suspicious activities?如何跟踪集群上的 kubectl 执行以监控是否有任何可疑活动?

As suggested by @P Use audit logs , as previously mentioned in the comments, to obtain the complete history beginning with the creation of a cluster.正如@P 所建议的那样,如前面评论中提到的那样,使用审计日志来获取从创建集群开始的完整历史记录。

In addition, you might be able to version control all of your cluster's state if you use gitops.此外,如果您使用 gitops,您可能能够对集群的所有状态进行版本控制。 You'll be able to track down every change to your cluster with this.您将能够使用它跟踪集群的每个更改。

Kubernetes likewise keeps a set of experiences (the length of which can likewise be controlled) for rollouts. Kubernetes 同样为推出保留了一组体验(其长度同样可以控制)。 The kubectl rollout command lets you see a rollout's state and its history. The kubectl rollout command可让您查看转出的状态及其历史记录。

It will have an explanation indicating their past arrangement changes.它将有一个解释表明他们过去的安排变化。 However, only one previous "version" is displayed.但是,只显示一个以前的“版本”。 You can search for ReplicaSets or run kubectl rollout history to find changes in deployment history.您可以搜索 ReplicaSets 或运行kubectl rollout history来查找部署历史中的更改。

When creating the deployment, use --record to initiate the replication of the deployment into the ReplicaSet.创建部署时,使用 --record 启动将部署复制到 ReplicaSet 中。

$ kubectl create -f deploy.yaml --record=true

The replica set keeps the deployment's previous configuration even when a new version is deployed.即使部署了新版本,副本集也会保留部署的先前配置。 Check out the deployment track;查看部署轨迹; even we can automate this.甚至我们可以将其自动化。 In the kubernetes deployment, this ought to be the default choice, but it is set to false by default.在 kubernetes 部署中,这应该是默认选择,但默认设置为 false。

The following commands can then be used to check the status and history:然后可以使用以下命令检查状态和历史记录:

$ kubectl rollout status deploy myapp-deployment 
$ kubectl rollout history deploy myapp-deployment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM