第32节 kubernetes 目录结构


❤️💕💕新时代拥抱云原生,云原生具有环境统一、按需付费、即开即用、稳定性强特点。Myblog:http://nsddd.topopen in new window


[TOC]

分类

Kubernetes的代码都在kubernetes目录下,如图,根据功能主要分成以下几类: 1、文档类(api、docs、logo) 2、工具类(build、cluster、Godeps、hack、staging、translations) 3、代码类(cmd、pkg、plugin、test、third_party)

工具类主要用到的build目录下的文件,自己动手编译的时候会用到;

核心代码集中在cmd和pkg中。

cmd内部包含各个组件的入口,具体核心的实现部分在pkg目录下。

我们每一个 可执行文件都对应 cmd

关于其他目录:

plugin 目录之前的版本包括 scheduler 部分的代码,当前版本(应该是在1.10之后)已经将scheduler部分代码移到和其他组件一致的 pkg 目录,所以目前 plugin 主要包含的是认证鉴权部分的代码。

根目录

root@cubmaster01:~/go/src/k8s.io/kubernetes# tree -L 1
.
├── api
├── build
├── CHANGELOG
├── CHANGELOG.md -> CHANGELOG/README.md
├── cluster
├── cmd
├── code-of-conduct.md
├── CONTRIBUTING.md
├── docs
├── go.mod
├── go.sum
├── hack
├── LICENSE
├── LICENSES
├── logo
├── Makefile -> build/root/Makefile
├── Makefile.generated_files -> build/root/Makefile.generated_files
├── _output
├── OWNERS
├── OWNERS_ALIASES
├── pkg
├── plugin
├── README.md
├── SECURITY_CONTACTS
├── staging
├── SUPPORT.md
├── test
├── third_party
└── vendor

pkg

提示

大量的 kubernetes 的源码所在,除了被抽离为单独组件的部分,例如 api server 的代码,proxy 组件的代码,kubelet 组件的代码。

  • 业务逻辑都在 pkg
  • 命令行参数都在 cmd

关于两个组件: ./pkg/api./pkg/apis

注意

Api 文件夹下包含和Open API 相关的模型定义等内容。

名称不一样,作用是完全不一样的。

  • 用于根据 OpenAPI 规范形成符合其规定的 API

  • apis 是包含内建 API Groups 和 API Objects 的,而 scheme 相关的代码大部分在这里。

root@cubmaster01:~/go/src/k8s.io/kubernetes# tree -L 1 pkg
pkg
├── api
├── apis
├── auth
├── capabilities
├── client
├── cloudprovider
├── cluster
├── controller
├── controlplane
├── credentialprovider
├── features
├── fieldpath
├── generated
├── kubeapiserver
├── kubectl
├── kubelet
├── kubemark
├── OWNERS
├── printers
├── probe
├── proxy
├── quota
├── registry
├── routes
├── scheduler
├── security
├── securitycontext
├── serviceaccount
├── util
├── volume
└── windows

cmd

root@cubmaster01:~/go/src/k8s.io/kubernetes# tree -L 1 cmd
cmd
├── clicheck
├── cloud-controller-manager
├── dependencycheck
├── dependencyverifier
├── gendocs
├── genkubedocs
├── genman
├── genswaggertypedocs
├── genutils
├── genyaml
├── importverifier
├── kubeadm
├── kube-apiserver
├── kube-controller-manager
├── kubectl
├── kubectl-convert
├── kubelet
├── kubemark
├── kube-proxy
├── kube-scheduler
├── linkcheck
├── OWNERS
├── preferredimports
├── prune-junit-xml
└── yamlfmt

提示

kube-apiserver 中有 apiserver.go 文件,就是 apiserver 启动入口

build

root@cubmaster01:~/go/src/k8s.io/kubernetes# tree -L 1 build
build
├── build-image
├── common.sh
├── copy-output.sh
├── dependencies.yaml
├── lib
├── make-build-image.sh
├── make-clean.sh
├── nsswitch.conf
├── OWNERS
├── package-tarballs.sh
├── pause
├── README.md
├── release-images.sh
├── release-in-a-container.sh
├── release.sh
├── root
├── run.sh
├── server-image
├── shell.sh
├── tools.go
└── util.sh

vendor

root@cubmaster01:~/go/src/k8s.io/kubernetes# tree -L 1 vendor/
vendor/
├── bitbucket.org
├── cloud.google.com
├── github.com
├── go.etcd.io
├── golang.org
├── gonum.org
├── google.golang.org
├── go.opencensus.io
├── go.opentelemetry.io
├── gopkg.in
├── go.starlark.net
├── go.uber.org
├── k8s.io
├── modules.txt
├── OWNERS
└── sigs.k8s.io

hack

root@cubmaster01:~/go/src/k8s.io/kubernetes# tree -L 1 hack/
hack/
├── benchmark-go.sh
├── boilerplate
├── build-cross.sh
├── build-go.sh
├── cherry_pick_pull.sh
├── conformance
├── dev-build-and-push.sh
├── dev-build-and-up.sh
├── dev-push-conformance.sh
├── e2e-internal
├── e2e-node-test.sh
├── generate-docs.sh
├── gen-swagger-doc
├── get-build.sh
├── ginkgo-e2e.sh
├── grab-profiles.sh
├── install-etcd.sh
├── jenkins
├── lib
├── lint-dependencies.sh
├── list-feature-tests.sh
├── local-up-cluster.sh
├── logcheck.conf
├── make-rules
├── module-graph.sh
├── OWNERS
├── pin-dependency.sh
├── print-workspace-status.sh
├── README.md
├── run-in-gopath.sh
├── run-prometheus-on-etcd-scrapes.sh
├── serve-prom-scrapes.sh
├── testdata
├── test-go.sh
├── test-integration.sh
├── tools
├── unwanted-dependencies.json
├── update-all.sh
├── update-codegen.sh
├── update-conformance-yaml.sh
├── update-generated-api-compatibility-data.sh
├── update-generated-device-plugin-dockerized.sh
├── update-generated-device-plugin.sh
├── update-generated-docs.sh
├── update-generated-kms-dockerized.sh
├── update-generated-kms.sh
├── update-generated-kubelet-plugin-registration-dockerized.sh
├── update-generated-kubelet-plugin-registration.sh
├── update-generated-pod-resources-dockerized.sh
├── update-generated-pod-resources.sh
├── update-generated-protobuf-dockerized.sh
├── update-generated-protobuf.sh
├── update-generated-runtime-dockerized.sh
├── update-generated-runtime.sh
├── update-generated-stable-metrics.sh
├── update-generated-swagger-docs.sh
├── update-gofmt.sh
├── update-import-aliases.sh
├── update-internal-modules.sh
├── update-kustomize.sh
├── update-mocks.sh
├── update-netparse-cve.sh
├── update-openapi-spec.sh
├── update-translations.sh
├── update-vendor-licenses.sh
├── update-vendor.sh
├── update-yamlfmt.sh
├── verify-all.sh
├── verify-api-groups.sh
├── verify-boilerplate.sh
├── verify-cli-conventions.sh
├── verify-codegen.sh
├── verify-conformance-requirements.sh
├── verify-conformance-yaml.sh
├── verify-description.sh
├── verify-e2e-test-ownership.sh
├── verify-external-dependencies-version.sh
├── verify-flags
├── verify-flags-underscore.py
├── verify-generated-device-plugin.sh
├── verify-generated-docs.sh
├── verify-generated-files-remake.sh
├── verify-generated-files.sh
├── verify-generated-kms.sh
├── verify-generated-kubelet-plugin-registration.sh
├── verify-generated-pod-resources.sh
├── verify-generated-protobuf.sh
├── verify-generated-runtime.sh
├── verify-generated-stable-metrics.sh
├── verify-generated-swagger-docs.sh
├── verify-gofmt.sh
├── verify-golangci-lint.sh
├── verify-govet-levee.sh
├── verify-govet.sh
├── verify-import-aliases.sh
├── verify-import-boss.sh
├── verify-imports.sh
├── verify-internal-modules.sh
├── verify-linkcheck.sh
├── verify-mocks.sh
├── verify-netparse-cve.sh
├── verify-non-mutating-validation.sh
├── verify-no-vendor-cycles.sh
├── verify-openapi-spec.sh
├── verify-pkg-names.sh
├── verify-prerelease-lifecycle-tags.sh
├── verify-prometheus-imports.sh
├── verify-publishing-bot.py
├── verify-readonly-packages.sh
├── verify-shellcheck.sh
├── verify-spelling.sh
├── verify-staging-meta-files.sh
├── verify-test-code.sh
├── verify-test-featuregates.sh
├── verify-test-images.sh
├── verify-typecheck-providerless.sh
├── verify-typecheck.sh
├── verify-vendor-licenses.sh
├── verify-vendor.sh
└── verify-yamlfmt.sh

plugin

plugin目录之前的版本包括 scheduler 部分的代码,当前版本(应该是在1.10之后)已经将scheduler部分代码移到和其他组件一致的pkg目录,所以目前 plugin 主要包含的是认证鉴权部分的代码。

root@cubmaster01:~/go/src/k8s.io/kubernetes# tree plugin/ -L 4
plugin/
├── OWNERS
└── pkg
    ├── admission
    │   ├── admit
    │   │   ├── admission.go
    │   │   └── admission_test.go
    │   ├── alwayspullimages
    │   │   ├── admission.go
    │   │   └── admission_test.go
    │   ├── antiaffinity
    │   │   ├── admission.go
    │   │   ├── admission_test.go
    │   │   └── doc.go
    │   ├── certificates
    │   │   ├── approval
    │   │   ├── OWNERS
    │   │   ├── signing
    │   │   ├── subjectrestriction
    │   │   └── util.go
    │   ├── defaulttolerationseconds
    │   │   ├── admission.go
    │   │   └── admission_test.go
    │   ├── deny
    │   │   ├── admission.go
    │   │   └── admission_test.go
    │   ├── eventratelimit
    │   │   ├── admission.go
    │   │   ├── admission_test.go
    │   │   ├── apis
    │   │   ├── cache.go
    │   │   ├── cache_test.go
    │   │   ├── config.go
    │   │   ├── doc.go
    │   │   └── limitenforcer.go
    │   ├── extendedresourcetoleration
    │   │   ├── admission.go
    │   │   └── admission_test.go
    │   ├── gc
    │   │   ├── gc_admission.go
    │   │   └── gc_admission_test.go
    │   ├── imagepolicy
    │   │   ├── admission.go
    │   │   ├── admission_test.go
    │   │   ├── certs_test.go
    │   │   ├── config.go
    │   │   ├── config_test.go
    │   │   ├── doc.go
    │   │   ├── gencerts.sh
    │   │   └── OWNERS
    │   ├── limitranger
    │   │   ├── admission.go
    │   │   ├── admission_test.go
    │   │   └── interfaces.go
    │   ├── namespace
    │   │   ├── autoprovision
    │   │   └── exists
    │   ├── network
    │   │   ├── defaultingressclass
    │   │   └── denyserviceexternalips
    │   ├── noderestriction
    │   │   ├── admission.go
    │   │   ├── admission_test.go
    │   │   └── OWNERS
    │   ├── nodetaint
    │   │   ├── admission.go
    │   │   └── admission_test.go
    │   ├── OWNERS
    │   ├── podnodeselector
    │   │   ├── admission.go
    │   │   └── admission_test.go
    │   ├── podtolerationrestriction
    │   │   ├── admission.go
    │   │   ├── admission_test.go
    │   │   ├── apis
    │   │   ├── config.go
    │   │   └── doc.go
    │   ├── priority
    │   │   ├── admission.go
    │   │   └── admission_test.go
    │   ├── resourcequota
    │   │   └── admission_test.go
    │   ├── runtimeclass
    │   │   ├── admission.go
    │   │   ├── admission_test.go
    │   │   └── OWNERS
    │   ├── security
    │   │   ├── doc.go
    │   │   ├── podsecurity
    │   │   └── podsecuritypolicy
    │   ├── securitycontext
    │   │   └── scdeny
    │   ├── serviceaccount
    │   │   ├── admission.go
    │   │   ├── admission_test.go
    │   │   ├── doc.go
    │   │   └── OWNERS
    │   └── storage
    │       ├── persistentvolume
    │       ├── storageclass
    │       └── storageobjectinuseprotection
    └── auth
        ├── authenticator
        │   ├── OWNERS
        │   └── token
        ├── authorizer
        │   ├── doc.go
        │   ├── node
        │   ├── OWNERS
        │   └── rbac
        ├── doc.go
        └── OWNERS

END 链接