要点01:软件配置项的起源次要有2块:命令行参数 和 配置文件k8s中的组件个别都是遵循下面的模式咱们以kube-scheduler为例命令参数举例 :能够看到--xxx=xxx的传参,当然所有参数都是有默认值的,如果你不传就走默认/usr/local/bin/kube-scheduler --log-dir=/var/log/k8s --logtostderr=false --alsologtostderr=true --config=/etc/k8s/kube-scheduler.yaml --kube-api-qps=500 --kube-api-burst=500 --authentication-kubeconfig=/etc/k8s/scheduler.conf --authorization-kubeconfig=/etc/k8s/scheduler.conf --kubeconfig=/etc/k8s/scheduler.conf --leader-elect=true --v=2下面的命令行参数中能够看到--config=xxx.yaml指定了 配置文件的门路比方咱们能够查看 这个配置文件的内容 :发现根本就是官网的默认配置cat /etc/k8s/kube-scheduler.yamlapiVersion: kubescheduler.config.k8s.io/v1beta1kind: KubeSchedulerConfigurationclientConnection: kubeconfig: "/etc/k8s/scheduler.conf"leaderElection: leaderElect: truemetricsBindAddress: 0.0.0.0:10251要点02:k8s组件提供了一个利用运行时查看失效配置的接口思考为何要提供?次要起因有上面几点
来自命令行和配置文件的配置2块可能有些笼罩的中央配置我的项目太多了在没有配置热更新的状况下:查看变更是否失效:
配置文件曾经更改,但遗记是利用重启前还是重启后改的了所以考究的我的项目外面都会留有一个http接口间接将以后利用内存中失效的配置我的项目打印进去,不便排查问题所以咱们前面写golang的我的项目也能够仿照这个接口要点03 : 如何申请scheduler的配置接口k8s组件对应查看配置的接口就是configz拜访组件接口须要鉴权,咱们能够通过sa来实现如何在1.24集群中创立rbacapiVersion: rbac.authorization.k8s.io/v1 # api的versionkind: ClusterRole # 类型metadata: name: prometheusrules:- apiGroups: [""] resources: # 资源 - nodes - nodes/metrics - nodes/proxy - services - endpoints - pods verbs: ["get", "list", "watch"] - apiGroups: - extensions resources: - ingresses verbs: ["get", "list", "watch"]- nonResourceURLs: ["/metrics"] verbs: ["get"]---apiVersion: v1kind: ServiceAccountmetadata: name: prometheus # 自定义名字 namespace: kube-system # 命名空间---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: prometheusroleRef: # 抉择须要绑定的Role apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: prometheussubjects: # 对象- kind: ServiceAccount name: prometheus namespace: kube-system---apiVersion: v1kind: Secretmetadata: namespace: kube-system name: prometheus annotations: kubernetes.io/service-account.name: prometheustype: kubernetes.io/service-account-token获取token命令root@k8s-master01:~# TOKEN=$(kubectl -n kube-system get secret prometheus -o jsonpath='{.data.token}'| base64 --decode )root@k8s-master01:~# echo $TOKENeyJhbGciOiJSUzI1NiIsImtpZCI6ImFVMS1mYlhobWIxcF92djBwbUIxZDhTVlFWd0VNa3VpNDlmOUhqcG9qSlkifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJwcm9tZXRoZXVzIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6InByb21ldGhldXMiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI2OTg2NWUwYy0yOGE4LTQ3YTEtYWEzYy03NThmNDlkYjA1YWUiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06cHJvbWV0aGV1cyJ9.SlORtZtVvLptYWE3zvblaOMxHNMBrHVTTHra7fO1RrwxdK3Bzc42ETLvkzVfQmAQlWrq5yiB4HiKFLe4qY2KVwK3qLDS_sWADLI16Sv8-O1Dt0oOQ0UZD0VOSGY0XEq2EGUxgxnx_JWllgEuMd0rjxtAtyjFh9wjCo_07lFCj44BffGGFp6Kovd8Dl_CJKpORakaJW-haIvTmTlbFPbRKojRTyKvtNCVn0zIXsz8Esp7z9XZmtUvZmHqNlY7bAFtGM9qLWUY_PkM1C0lQ2ZDKASdhZpx6LJr1Wo4WSNILCVfECT0sd6TnFHbgd1NwBc0kcTct5VbST76AJwUpG5esA在http申请中把下面的TOKEN 作为beare-token传过来就能够了申请的curl命令如下(在kube-scheduler部署的节点上执行,通常是master)curl -k -s https://localhost:10259/configz --header "Authorization: Bearer $TOKEN" |python -m json.tool要点04 依据返回的json配置段来剖析插件开启的状况json数据如下{ "componentconfig": { "AlgorithmSource": { "Policy": null, "Provider": "DefaultProvider" }, "ClientConnection": { "AcceptContentTypes": "", "Burst": 100, "ContentType": "application/vnd.kubernetes.protobuf", "Kubeconfig": "/etc/k8s/scheduler.conf", "QPS": 50 }, "EnableContentionProfiling": true, "EnableProfiling": true, "Extenders": null, "HealthzBindAddress": "0.0.0.0:10251", "LeaderElection": { "LeaderElect": true, "LeaseDuration": "15s", "RenewDeadline": "10s", "ResourceLock": "leases", "ResourceName": "kube-scheduler", "ResourceNamespace": "kube-system", "RetryPeriod": "2s" }, "MetricsBindAddress": "0.0.0.0:10251", "Parallelism": 16, "PercentageOfNodesToScore": 0, "PodInitialBackoffSeconds": 1, "PodMaxBackoffSeconds": 10, "Profiles": [ { "PluginConfig": [ { "Args": { "MinCandidateNodesAbsolute": 100, "MinCandidateNodesPercentage": 10 }, "Name": "DefaultPreemption" }, { "Args": { "HardPodAffinityWeight": 1 }, "Name": "InterPodAffinity" }, { "Args": { "AddedAffinity": null }, "Name": "NodeAffinity" }, { "Args": { "IgnoredResourceGroups": null, "IgnoredResources": null }, "Name": "NodeResourcesFit" }, { "Args": { "Resources": [ { "Name": "cpu", "Weight": 1 }, { "Name": "memory", "Weight": 1 } ] }, "Name": "NodeResourcesLeastAllocated" }, { "Args": { "DefaultConstraints": null, "DefaultingType": "System" }, "Name": "PodTopologySpread" }, { "Args": { "BindTimeoutSeconds": 600 }, "Name": "VolumeBinding" } ], "Plugins": { "Bind": { "Disabled": null, "Enabled": [ { "Name": "DefaultBinder", "Weight": 0 } ] }, "Filter": { "Disabled": null, "Enabled": [ { "Name": "NodeUnschedulable", "Weight": 0 }, { "Name": "NodeName", "Weight": 0 }, { "Name": "TaintToleration", "Weight": 0 }, { "Name": "NodeAffinity", "Weight": 0 }, { "Name": "NodePorts", "Weight": 0 }, { "Name": "NodeResourcesFit", "Weight": 0 }, { "Name": "VolumeRestrictions", "Weight": 0 }, { "Name": "EBSLimits", "Weight": 0 }, { "Name": "GCEPDLimits", "Weight": 0 }, { "Name": "NodeVolumeLimits", "Weight": 0 }, { "Name": "AzureDiskLimits", "Weight": 0 }, { "Name": "VolumeBinding", "Weight": 0 }, { "Name": "VolumeZone", "Weight": 0 }, { "Name": "PodTopologySpread", "Weight": 0 }, { "Name": "InterPodAffinity", "Weight": 0 } ] }, "Permit": { "Disabled": null, "Enabled": null }, "PostBind": { "Disabled": null, "Enabled": null }, "PostFilter": { "Disabled": null, "Enabled": [ { "Name": "DefaultPreemption", "Weight": 0 } ] }, "PreBind": { "Disabled": null, "Enabled": [ { "Name": "VolumeBinding", "Weight": 0 } ] }, "PreFilter": { "Disabled": null, "Enabled": [ { "Name": "NodeResourcesFit", "Weight": 0 }, { "Name": "NodePorts", "Weight": 0 }, { "Name": "PodTopologySpread", "Weight": 0 }, { "Name": "InterPodAffinity", "Weight": 0 }, { "Name": "VolumeBinding", "Weight": 0 } ] }, "PreScore": { "Disabled": null, "Enabled": [ { "Name": "InterPodAffinity", "Weight": 0 }, { "Name": "PodTopologySpread", "Weight": 0 }, { "Name": "TaintToleration", "Weight": 0 } ] }, "QueueSort": { "Disabled": null, "Enabled": [ { "Name": "PrioritySort", "Weight": 0 } ] }, "Reserve": { "Disabled": null, "Enabled": [ { "Name": "VolumeBinding", "Weight": 0 } ] }, "Score": { "Disabled": null, "Enabled": [ { "Name": "NodeResourcesBalancedAllocation", "Weight": 1 }, { "Name": "ImageLocality", "Weight": 1 }, { "Name": "InterPodAffinity", "Weight": 1 }, { "Name": "NodeResourcesLeastAllocated", "Weight": 1 }, { "Name": "NodeAffinity", "Weight": 1 }, { "Name": "NodePreferAvoidPods", "Weight": 10000 }, { "Name": "PodTopologySpread", "Weight": 2 }, { "Name": "TaintToleration", "Weight": 1 } ] } }, "SchedulerName": "default-scheduler" } ] }}前置常识 k8s的调度框架 scheduler framework文档地位这张架构图肯定要烂熟于心 咱们发现在 componentconfig.Profiles其实次要分两块:Plugins段代表调度框架每个扩大点的插件开启和禁用的状况:
...