如何查看k8s存在etcd中的数据?

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Tair(兼容Redis),内存型 2GB
容器服务 Serverless 版 ACK Serverless,317元额度 多规格
简介: 一直有这个冲动, 想知道kubernetes往etcd里放了哪些数据,是如何组织的。 能看到,才有把握知道它的实现和细节。 找了很多文档,终于找到靠谱的。

一直有这个冲动,

想知道kubernetes往etcd里放了哪些数据,是如何组织的。

能看到,才有把握知道它的实现和细节。

找了很多文档,终于找到靠谱的。

===========================

https://www.jianshu.com/p/f9f83dd21770

===========================


我是使用kubeadm工具安装的集群,要解除集群的资源占用要先把一些容器停掉,把kube-apiserver的编排文件从/etc/kubernetes/manifests/目录下先移出来,kubelet检查到会停止相应的pods,没有了kube-apiserver集群不会再创建新的pods,这时kubectl不可用了,使用docker命令把spinnaker项目的容器都删掉系统资源就能空闲出来。这时etcd还是正常的,用docker工具直接进入etcd。
操作etcd有命令行工具 etcdctl,有两个api版本互不兼容的,系统默认的v2版本,kubernetes集群使用的是v3版本,v2版本下是看不到v3版本的数据的,我也是找了些资料才了解这个情况。
使用环境变量定义api版本
export ETCDCTL_API=3
etcd有目录结构类似linux文件系统,获取所有key看一看:
etcdctl get / --prefix --keys-only


一看就可以大概理解kubenetes的数据结构了,查询命名空间下所有部署的数据:
etcdctl get /registry/deployments/default --prefix --keys-only
把想删除的删掉,列如:
etcdctl del /registry/deployments/default/elevated-dragonfly-spinn-front50
删除deployments,pods这可以了,稍微减少一些资源,让kube-apiserver可以正常工作即可,其它资源还可以使用kubectl工具删除
删掉些资源后退出etcd把kube-apiserver的编排文件放回/etc/kubernetes/manifests目录,服务会再次启动,然后再清理重新部署。


=======================================
k8s 1.9.3放在etcd里的根数据结构如下:

etcdctl get / --prefix --keys-only

/registry/apiregistration.k8s.io/apiservices/v1.

/registry/apiregistration.k8s.io/apiservices/v1.apps

/registry/apiregistration.k8s.io/apiservices/v1.authentication.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1.authorization.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1.autoscaling

/registry/apiregistration.k8s.io/apiservices/v1.batch

/registry/apiregistration.k8s.io/apiservices/v1.networking.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1.rbac.authorization.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1.storage.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1beta1.admissionregistration.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1beta1.apiextensions.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1beta1.apps

/registry/apiregistration.k8s.io/apiservices/v1beta1.authentication.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1beta1.authorization.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1beta1.batch

/registry/apiregistration.k8s.io/apiservices/v1beta1.certificates.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1beta1.events.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1beta1.extensions

/registry/apiregistration.k8s.io/apiservices/v1beta1.policy

/registry/apiregistration.k8s.io/apiservices/v1beta1.rbac.authorization.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1beta1.storage.k8s.io

/registry/apiregistration.k8s.io/apiservices/v1beta2.apps

/registry/apiregistration.k8s.io/apiservices/v2beta1.autoscaling

/registry/certificatesigningrequests/node-csr-NMpLG7rhBYiuAyRD739h79x2qhbhWn-UtLPFwJWJU1Y

/registry/certificatesigningrequests/node-csr-v96LRHUfeRD3iAZgHdUYxDaT1kkHvIilDnLZy2GPSew

/registry/clusterrolebindings/cluster-admin

/registry/clusterrolebindings/flannel

/registry/clusterrolebindings/heapster

/registry/clusterrolebindings/kubeadm:kubelet-bootstrap

/registry/clusterrolebindings/kubeadm:node-autoapprove-bootstrap

/registry/clusterrolebindings/kubeadm:node-autoapprove-certificate-rotation

/registry/clusterrolebindings/kubeadm:node-proxier

/registry/clusterrolebindings/kubernetes-dashboard

/registry/clusterrolebindings/system:aws-cloud-provider

/registry/clusterrolebindings/system:basic-user

/registry/clusterrolebindings/system:controller:attachdetach-controller

/registry/clusterrolebindings/system:controller:certificate-controller

/registry/clusterrolebindings/system:controller:clusterrole-aggregation-controller

/registry/clusterrolebindings/system:controller:cronjob-controller

/registry/clusterrolebindings/system:controller:daemon-set-controller

/registry/clusterrolebindings/system:controller:deployment-controller

/registry/clusterrolebindings/system:controller:disruption-controller

/registry/clusterrolebindings/system:controller:endpoint-controller

/registry/clusterrolebindings/system:controller:generic-garbage-collector

/registry/clusterrolebindings/system:controller:horizontal-pod-autoscaler

/registry/clusterrolebindings/system:controller:job-controller

/registry/clusterrolebindings/system:controller:namespace-controller

/registry/clusterrolebindings/system:controller:node-controller

/registry/clusterrolebindings/system:controller:persistent-volume-binder

/registry/clusterrolebindings/system:controller:pod-garbage-collector

/registry/clusterrolebindings/system:controller:replicaset-controller

/registry/clusterrolebindings/system:controller:replication-controller

/registry/clusterrolebindings/system:controller:resourcequota-controller

/registry/clusterrolebindings/system:controller:route-controller

/registry/clusterrolebindings/system:controller:service-account-controller

/registry/clusterrolebindings/system:controller:service-controller

/registry/clusterrolebindings/system:controller:statefulset-controller

/registry/clusterrolebindings/system:controller:ttl-controller

/registry/clusterrolebindings/system:coredns

/registry/clusterrolebindings/system:discovery

/registry/clusterrolebindings/system:kube-controller-manager

/registry/clusterrolebindings/system:kube-dns

/registry/clusterrolebindings/system:kube-scheduler

/registry/clusterrolebindings/system:node

/registry/clusterrolebindings/system:node-proxier

/registry/clusterroles/admin

/registry/clusterroles/cluster-admin

/registry/clusterroles/edit

/registry/clusterroles/flannel

/registry/clusterroles/system:aggregate-to-admin

/registry/clusterroles/system:aggregate-to-edit

/registry/clusterroles/system:aggregate-to-view

/registry/clusterroles/system:auth-delegator

/registry/clusterroles/system:aws-cloud-provider

/registry/clusterroles/system:basic-user

/registry/clusterroles/system:certificates.k8s.io:certificatesigningrequests:nodeclient

/registry/clusterroles/system:certificates.k8s.io:certificatesigningrequests:selfnodeclient

/registry/clusterroles/system:controller:attachdetach-controller

/registry/clusterroles/system:controller:certificate-controller

/registry/clusterroles/system:controller:clusterrole-aggregation-controller

/registry/clusterroles/system:controller:cronjob-controller

/registry/clusterroles/system:controller:daemon-set-controller

/registry/clusterroles/system:controller:deployment-controller

/registry/clusterroles/system:controller:disruption-controller

/registry/clusterroles/system:controller:endpoint-controller

/registry/clusterroles/system:controller:generic-garbage-collector

/registry/clusterroles/system:controller:horizontal-pod-autoscaler

/registry/clusterroles/system:controller:job-controller

/registry/clusterroles/system:controller:namespace-controller

/registry/clusterroles/system:controller:node-controller

/registry/clusterroles/system:controller:persistent-volume-binder

/registry/clusterroles/system:controller:pod-garbage-collector

/registry/clusterroles/system:controller:replicaset-controller

/registry/clusterroles/system:controller:replication-controller

/registry/clusterroles/system:controller:resourcequota-controller

/registry/clusterroles/system:controller:route-controller

/registry/clusterroles/system:controller:service-account-controller

/registry/clusterroles/system:controller:service-controller

/registry/clusterroles/system:controller:statefulset-controller

/registry/clusterroles/system:controller:ttl-controller

/registry/clusterroles/system:coredns

/registry/clusterroles/system:discovery

/registry/clusterroles/system:heapster

/registry/clusterroles/system:kube-aggregator

/registry/clusterroles/system:kube-controller-manager

/registry/clusterroles/system:kube-dns

/registry/clusterroles/system:kube-scheduler

/registry/clusterroles/system:node

/registry/clusterroles/system:node-bootstrapper

/registry/clusterroles/system:node-problem-detector

/registry/clusterroles/system:node-proxier

/registry/clusterroles/system:persistent-volume-provisioner

/registry/clusterroles/view

/registry/configmaps/kube-public/cluster-info

/registry/configmaps/kube-system/coredns

/registry/configmaps/kube-system/extension-apiserver-authentication

/registry/configmaps/kube-system/kube-flannel-cfg

/registry/configmaps/kube-system/kube-proxy

/registry/configmaps/kube-system/kubeadm-config

/registry/configmaps/kube-system/kubernetes-dashboard-settings

/registry/controllerrevisions/kube-system/kube-flannel-ds-dd8484577

/registry/controllerrevisions/kube-system/kube-proxy-95cfb667c

/registry/cronjobs/default/hello

/registry/daemonsets/kube-system/kube-flannel-ds

/registry/daemonsets/kube-system/kube-proxy

/registry/deployments/default/flower

/registry/deployments/default/pc-saveapi

/registry/deployments/default/pxxxm-django

/registry/deployments/default/pxxxm-redis

/registry/deployments/default/pxxxm-tengine-proxy

/registry/deployments/default/pxxxm-tengine-static

/registry/deployments/default/pxxxmlogapi-nj

/registry/deployments/kube-system/coredns

/registry/deployments/kube-system/heapster

/registry/deployments/kube-system/kubernetes-dashboard

/registry/deployments/kube-system/monitoring-grafana

/registry/deployments/kube-system/monitoring-influxdb

/registry/events/default/flower-554b58b968-n48sj.151de36ccc190d41

/registry/events/default/flower-554b58b968-n48sj.151de36e0d128ca9

/registry/events/default/hello.151e1bcd521ee391

/registry/jobs/default/hello-1521622920

/registry/jobs/default/hello-1521622980

/registry/jobs/default/hello-1521623040

/registry/minions/cnsz131381

/registry/minions/cnsz131382

/registry/minions/cnsz131383

/registry/namespaces/default

/registry/namespaces/kube-public

/registry/namespaces/kube-system

/registry/pods/default/flower-554b58b968-n48sj

/registry/pods/default/hello-1521622920-5z4bl

/registry/pods/default/hello-1521622980-4qcrd

/registry/pods/default/hello-1521623040-szf4f

/registry/pods/default/pc-saveapi-58cf87b4f5-5x2d8

/registry/pods/default/pxxxm-django-8466f46d84-4mjtf

/registry/pods/default/pxxxm-django-8466f46d84-pnqzp

/registry/pods/default/pxxxm-django-8466f46d84-x5d8z

/registry/pods/default/pxxxm-redis-767c5d5966-l88qj

/registry/pods/default/pxxxm-tengine-proxy-75d874d898-8275h

/registry/pods/default/pxxxm-tengine-static-7d7bb5d5b6-7568z

/registry/pods/default/pxxxmlogapi-nj-687cc89b96-ps4np

/registry/pods/kube-system/coredns-65dcdb4cf-hgmdv

/registry/pods/kube-system/etcd-cnsz131383

/registry/pods/kube-system/heapster-5996df699d-d8798

/registry/pods/kube-system/kube-apiserver-cnsz131383

/registry/pods/kube-system/kube-controller-manager-cnsz131383

/registry/pods/kube-system/kube-flannel-ds-gr8jp

/registry/pods/kube-system/kube-flannel-ds-p4tpq

/registry/pods/kube-system/kube-flannel-ds-z7s96

/registry/pods/kube-system/kube-proxy-cgjhk

/registry/pods/kube-system/kube-proxy-f7snz

/registry/pods/kube-system/kube-proxy-l98gl

/registry/pods/kube-system/kube-scheduler-cnsz131383

/registry/pods/kube-system/kubernetes-dashboard-5bd6f767c7-vr6sg

/registry/pods/kube-system/monitoring-grafana-6bf544559d-cd6d4

/registry/pods/kube-system/monitoring-influxdb-865d95895b-n9sls

/registry/ranges/serviceips

/registry/ranges/servicenodeports

/registry/replicasets/default/flower-554b58b968

/registry/replicasets/default/pc-saveapi-58cf87b4f5

/registry/replicasets/default/pxxxm-django-8466f46d84

/registry/replicasets/default/pxxxm-redis-767c5d5966

/registry/replicasets/default/pxxxm-tengine-proxy-75d874d898

/registry/replicasets/default/pxxxm-tengine-static-7d7bb5d5b6

/registry/replicasets/default/pxxxmlogapi-nj-687cc89b96

/registry/replicasets/kube-system/coredns-65dcdb4cf

/registry/replicasets/kube-system/heapster-5996df699d

/registry/replicasets/kube-system/kubernetes-dashboard-5bd6f767c7

/registry/replicasets/kube-system/monitoring-grafana-6bf544559d

/registry/replicasets/kube-system/monitoring-influxdb-865d95895b

/registry/rolebindings/kube-public/kubeadm:bootstrap-signer-clusterinfo

/registry/rolebindings/kube-public/system:controller:bootstrap-signer

/registry/rolebindings/kube-system/kubernetes-dashboard-minimal

/registry/rolebindings/kube-system/system::leader-locking-kube-controller-manager

/registry/rolebindings/kube-system/system::leader-locking-kube-scheduler

/registry/rolebindings/kube-system/system:controller:bootstrap-signer

/registry/rolebindings/kube-system/system:controller:cloud-provider

/registry/rolebindings/kube-system/system:controller:token-cleaner

/registry/roles/kube-public/kubeadm:bootstrap-signer-clusterinfo

/registry/roles/kube-public/system:controller:bootstrap-signer

/registry/roles/kube-system/extension-apiserver-authentication-reader

/registry/roles/kube-system/kubernetes-dashboard-minimal

/registry/roles/kube-system/system::leader-locking-kube-controller-manager

/registry/roles/kube-system/system::leader-locking-kube-scheduler

/registry/roles/kube-system/system:controller:bootstrap-signer

/registry/roles/kube-system/system:controller:cloud-provider

/registry/roles/kube-system/system:controller:token-cleaner

/registry/secrets/default/default-token-hfj82

/registry/secrets/kube-public/default-token-wpbfs

/registry/secrets/kube-system/attachdetach-controller-token-7jsks

/registry/secrets/kube-system/bootstrap-signer-token-xs87g

/registry/secrets/kube-system/certificate-controller-token-x4swr

/registry/secrets/kube-system/clusterrole-aggregation-controller-token-z7w85

/registry/secrets/kube-system/coredns-token-tbbbw

/registry/secrets/kube-system/cronjob-controller-token-p44bn

/registry/secrets/kube-system/daemon-set-controller-token-4klc2

/registry/secrets/kube-system/default-token-g9lcp

/registry/secrets/kube-system/deployment-controller-token-gfcdt

/registry/secrets/kube-system/disruption-controller-token-vs4dz

/registry/secrets/kube-system/endpoint-controller-token-92kn2

/registry/secrets/kube-system/flannel-token-wvgjq

/registry/secrets/kube-system/generic-garbage-collector-token-pcpnq

/registry/secrets/kube-system/heapster-token-6szhz

/registry/secrets/kube-system/horizontal-pod-autoscaler-token-xqcl5

/registry/secrets/kube-system/job-controller-token-422zr

/registry/secrets/kube-system/kube-proxy-token-k5rfq

/registry/secrets/kube-system/kubernetes-dashboard-certs

/registry/secrets/kube-system/kubernetes-dashboard-key-holder

/registry/secrets/kube-system/kubernetes-dashboard-token-kpkw7

/registry/secrets/kube-system/namespace-controller-token-r57ss

/registry/secrets/kube-system/node-controller-token-5f7sm

/registry/secrets/kube-system/persistent-volume-binder-token-7rnt2

/registry/secrets/kube-system/pod-garbage-collector-token-2txwf

/registry/secrets/kube-system/replicaset-controller-token-zh9xq

/registry/secrets/kube-system/replication-controller-token-q69jz

/registry/secrets/kube-system/resourcequota-controller-token-92hn4

/registry/secrets/kube-system/service-account-controller-token-vvw5d

/registry/secrets/kube-system/service-controller-token-lslnf

/registry/secrets/kube-system/statefulset-controller-token-wdqjt

/registry/secrets/kube-system/token-cleaner-token-9zzpv

/registry/secrets/kube-system/ttl-controller-token-tc7pl

/registry/serviceaccounts/default/default

/registry/serviceaccounts/kube-public/default

/registry/serviceaccounts/kube-system/attachdetach-controller

/registry/serviceaccounts/kube-system/bootstrap-signer

/registry/serviceaccounts/kube-system/certificate-controller

/registry/serviceaccounts/kube-system/clusterrole-aggregation-controller

/registry/serviceaccounts/kube-system/coredns

/registry/serviceaccounts/kube-system/cronjob-controller

/registry/serviceaccounts/kube-system/daemon-set-controller

/registry/serviceaccounts/kube-system/default

/registry/serviceaccounts/kube-system/deployment-controller

/registry/serviceaccounts/kube-system/disruption-controller

/registry/serviceaccounts/kube-system/endpoint-controller

/registry/serviceaccounts/kube-system/flannel

/registry/serviceaccounts/kube-system/generic-garbage-collector

/registry/serviceaccounts/kube-system/heapster

/registry/serviceaccounts/kube-system/horizontal-pod-autoscaler

/registry/serviceaccounts/kube-system/job-controller

/registry/serviceaccounts/kube-system/kube-proxy

/registry/serviceaccounts/kube-system/kubernetes-dashboard

/registry/serviceaccounts/kube-system/namespace-controller

/registry/serviceaccounts/kube-system/node-controller

/registry/serviceaccounts/kube-system/persistent-volume-binder

/registry/serviceaccounts/kube-system/pod-garbage-collector

/registry/serviceaccounts/kube-system/replicaset-controller

/registry/serviceaccounts/kube-system/replication-controller

/registry/serviceaccounts/kube-system/resourcequota-controller

/registry/serviceaccounts/kube-system/service-account-controller

/registry/serviceaccounts/kube-system/service-controller

/registry/serviceaccounts/kube-system/statefulset-controller

/registry/serviceaccounts/kube-system/token-cleaner

/registry/serviceaccounts/kube-system/ttl-controller

/registry/services/endpoints/default/flower

/registry/services/endpoints/default/kubernetes

/registry/services/endpoints/default/pc-saveapi

/registry/services/endpoints/default/pxxxm-django

/registry/services/endpoints/default/pxxxm-redis

/registry/services/endpoints/default/pxxxm-tengine-proxy

/registry/services/endpoints/default/pxxxm-tengine-static

/registry/services/endpoints/default/pxxxmlogapi-nj

/registry/services/endpoints/kube-system/heapster

/registry/services/endpoints/kube-system/kube-controller-manager

/registry/services/endpoints/kube-system/kube-dns

/registry/services/endpoints/kube-system/kube-scheduler

/registry/services/endpoints/kube-system/kubernetes-dashboard

/registry/services/endpoints/kube-system/monitoring-grafana

/registry/services/endpoints/kube-system/monitoring-influxdb

/registry/services/specs/default/flower

/registry/services/specs/default/kubernetes

/registry/services/specs/default/pc-saveapi

/registry/services/specs/default/pxxxm-django

/registry/services/specs/default/pxxxm-redis

/registry/services/specs/default/pxxxm-tengine-proxy

/registry/services/specs/default/pxxxm-tengine-static

/registry/services/specs/default/pxxxmlogapi-nj

/registry/services/specs/kube-system/heapster

/registry/services/specs/kube-system/kube-dns

/registry/services/specs/kube-system/kubernetes-dashboard

/registry/services/specs/kube-system/monitoring-grafana

/registry/services/specs/kube-system/monitoring-influxdb


相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
相关文章
|
2月前
|
存储 Kubernetes 关系型数据库
阿里云ACK备份中心,K8s集群业务应用数据的一站式灾备方案
阿里云ACK备份中心,K8s集群业务应用数据的一站式灾备方案
|
3月前
|
存储 Kubernetes 安全
Kubernetes 中如何对 etcd 进行备份和还原
Kubernetes 中如何对 etcd 进行备份和还原
|
3月前
|
存储 Kubernetes Cloud Native
告别数据丢失的噩梦!PersistentVolume全攻略,让你轻松玩转Kubernetes数据持久化秘籍!
【8月更文挑战第25天】随着容器技术的发展,Kubernetes已成为云原生应用的主流部署平台。然而,数据持久化成为一个亟待解决的问题。Kubernetes通过PersistentVolume(PV)提供了解决方案。PV是一种存储资源对象,它抽象出底层存储技术(例如Ceph、GlusterFS或NFS),让用户仅需关注存储容量和访问模式等属性。PV由管理员创建与维护,Pod通过PersistentVolumeClaim(PVC)请求存储资源。本文详细介绍了PV的工作原理、配置方法及示例,帮助读者更好地理解和应用此功能。
129 2
|
3月前
|
存储 Kubernetes 算法
在K8S中,etcd 及其特点?
在K8S中,etcd 及其特点?
|
3月前
|
存储 Kubernetes API
在K8S中,etcd 适应的场景?
在K8S中,etcd 适应的场景?
|
3月前
|
存储 Kubernetes 安全
在K8S中,你用的flannel是哪个工作模式及fannel的底层原理如何实现数据报文转发的?
在K8S中,你用的flannel是哪个工作模式及fannel的底层原理如何实现数据报文转发的?
|
3月前
|
C# Windows 开发者
超越选择焦虑:深入解析WinForms、WPF与UWP——谁才是打造顶级.NET桌面应用的终极利器?从开发效率到视觉享受,全面解读三大框架优劣,助你精准匹配项目需求,构建完美桌面应用生态系统
【8月更文挑战第31天】.NET框架为开发者提供了多种桌面应用开发选项,包括WinForms、WPF和UWP。WinForms简单易用,适合快速开发基本应用;WPF提供强大的UI设计工具和丰富的视觉体验,支持XAML,易于实现复杂布局;UWP专为Windows 10设计,支持多设备,充分利用现代硬件特性。本文通过示例代码详细介绍这三种框架的特点,帮助读者根据项目需求做出明智选择。以下是各框架的简单示例代码,便于理解其基本用法。
161 0
|
3月前
|
存储 Kubernetes 调度
在K8S中,是怎么实现数据持久化的?
在K8S中,是怎么实现数据持久化的?
|
23天前
|
JSON Kubernetes 容灾
ACK One应用分发上线:高效管理多集群应用
ACK One应用分发上线,主要介绍了新能力的使用场景
|
24天前
|
Kubernetes 持续交付 开发工具
ACK One GitOps:ApplicationSet UI简化多集群GitOps应用管理
ACK One GitOps新发布了多集群应用控制台,支持管理Argo CD ApplicationSet,提升大规模应用和集群的多集群GitOps应用分发管理体验。