本文系列:
kubernetes(k8s)容器集群管理环境完整部署详细教程-上篇
kubernetes(k8s)容器集群管理环境完整部署详细教程-中篇
kubernetes(k8s)容器集群管理环境完整部署详细教程-下篇
在前一篇文章中详细介绍了kubernetes(k8s)容器集群管理环境完整部署详细教程-中篇,这里继续记录下kubernetes集群插件等部署过程:
插件是kubernetes集群的附件组件,丰富和完善了集群的功能,这里分别介绍的插件有coredns、dashboard、metrics rver,需要注意的是:kuberntes 自带插件的 manifests yaml 文件使用 gcr.io 的 docker registry,国内被墙,需要手动替换为其它registry 地址或提前在fq服务器上下载,然后再同步到对应的k8s部署机器上。
可以从微软中国提供的 gcr.io免费代理下载被墙的镜像;下面部署命令均在k8s-master01节点上执行。
1)修改配置文件将下载的 kubernetes-rver-linux-amd64.tar.gz 解压后,再解压其中的 kubernetes-src.tar.gz 文件。[root@k8s-master01 ~]# cd /opt/k8s/work/kubernetes[root@k8s-master01 kubernetes]# tar -xzvf kubernetes-src.tar.gz解压之后,coredns 目录是 cluster/addons/dns。[root@k8s-master01 kubernetes]# cd /opt/k8s/work/kubernetes/cluster/addons/dns/coredns[root@k8s-master01 coredns]# cp coredns.yaml.ba coredns.yaml[root@k8s-master01 coredns]# source /opt/k8s/bin/environment.sh[root@k8s-master01 coredns]# d -i -e "s/__pillar__dns__domain__/${cluster_dns_domain}/" -e "s/__pillar__dns__rver__/${cluster_dns_svc_ip}/" coredns.yaml2)创建 coredns[root@k8s-master01 coredns]# fgrep "image" ./*./coredns.yaml: image: k8s.gcr.io/coredns:1.3.1./coredns.yaml: imagepullpolicy: ifnotprent./coredns.yaml.ba: image: k8s.gcr.io/coredns:1.3.1./coredns.yaml.ba: imagepullpolicy: ifnotprent./coredns.yaml.in: image: k8s.gcr.io/coredns:1.3.1./coredns.yaml.in: imagepullpolicy: ifnotprent./coredns.yaml.d: image: k8s.gcr.io/coredns:1.3.1./coredns.yaml.d: imagepullpolicy: ifnotprent提前fq下载"k8s.gcr.io/coredns:1.3.1"镜像,然后上传到node节点上, 执行"docker load ..."命令导入到node节点的images镜像里面或者从微软中国提供的gcr.io免费代理下载被墙的镜像,然后在修改yaml文件里更新coredns的镜像下载地址然后确保对应yaml文件里的镜像拉取策略为ifnotprent,即本地有则使用本地镜像,不拉取接着再次进行coredns的创建[root@k8s-master01 coredns]# kubectl create -f coredns.yaml3)检查coredns功能 (执行下面命令后,稍微等一会儿,确保ready状态都是可用的)[root@k8s-master01 coredns]# kubectl get all -n kube-systemname ready status restarts agepod/coredns-5b969f4c88-pd5js 1/1 running 0 55sname type cluster-ip external-ip port(s) agervice/kube-dns clusterip 10.254.0.2 <none> 53/udp,53/tcp,9153/tcp 56sname ready up-to-date available agedeployment.apps/coredns 1/1 1 1 57sname desired current ready agereplicat.apps/coredns-5b969f4c88 1 1 1 56s查看创建的coredns的pod状态,确保没有报错[root@k8s-master01 coredns]# kubectl describe pod/coredns-5b969f4c88-pd5js -n kube-system..........................events:type reason age from message---- ------ ---- ---- -------normal scheduled 2m12s default-scheduler successfully assigned kube-system/coredns-5b969f4c88-pd5js to k8s-node03normal pulled 2m11s kubelet, k8s-node03 container image "k8s.gcr.io/coredns:1.3.1" already prent on machinenormal created 2m10s kubelet, k8s-node03 created container corednsnormal started 2m10s kubelet, k8s-node03 started container coredns4)新建一个 deployment[root@k8s-master01 coredns]# cd /opt/k8s/work[root@k8s-master01 work]# cat > my-nginx.yaml <<eofapiversion: extensions/v1beta1kind: deploymentmetadata:name: my-nginxspec:replicas: 2template:metadata:labels:run: my-nginxspec:containers:- name: my-nginximage: nginx:1.7.9ports:- containerport: 80eof接着执行这个deployment的创建[root@k8s-master01 work]# kubectl create -f my-nginx.yamlexport 该 deployment, 生成 my-nginx 服务:[root@k8s-master01 work]# kubectl expo deploy my-nginx[root@k8s-master01 work]# kubectl get rvices --all-namespaces |grep my-nginxdefault my-nginx clusterip 10.254.170.246 <none> 80/tcp 19s创建另一个 pod,查看 /etc/resolv.conf 是否包含 kubelet 配置的 --cluster-dns 和 --cluster-domain,是否能够将服务 my-nginx 解析到上面显示的 cluster ip 10.254.170.246[root@k8s-master01 work]# cd /opt/k8s/work[root@k8s-master01 work]# cat > dnsutils-ds.yml <<eofapiversion: v1kind: rvicemetadata:name: dnsutils-dslabels:app: dnsutils-dsspec:type: nodeportlector:app: dnsutils-dsports:- name: httpport: 80targetport: 80---apiversion: extensions/v1beta1kind: daemontmetadata:name: dnsutils-dslabels:addonmanager.kubernetes.io/mode: reconcilespec:template:metadata:labels:app: dnsutils-dsspec:containers:- name: my-dnsutilsimage: tutum/dnsutils:latestcommand:- sleep- "3600"ports:- containerport: 80eof接着创建这个pod[root@k8s-master01 work]# kubectl create -f dnsutils-ds.yml查看上面创建的pod状态(需要等待一会儿,确保status状态为"running"。如果状态失败,可以执行"kubectl describe pod ...."查看原因)[root@k8s-master01 work]# kubectl get pods -lapp=dnsutils-dsname ready status restarts agednsutils-ds-5sc4z 1/1 running 0 52sdnsutils-ds-h546r 1/1 running 0 52sdnsutils-ds-jx5kx 1/1 running 0 52s[root@k8s-master01 work]# kubectl get svcname type cluster-ip external-ip port(s) agednsutils-ds nodeport 10.254.185.211 <none> 80:32767/tcp 7m14skubernetes clusterip 10.254.0.1 <none> 443/tcp 7d13hmy-nginx clusterip 10.254.170.246 <none> 80/tcp 9m11snginx-ds nodeport 10.254.41.83 <none> 80:30876/tcp 27h然后验证coredns 功能。先依次登陆上面创建的dnsutils的pod里面进行验证,确保pod容器中/etc/resolv.conf里的namerver地址为"cluster_dns_svc_ip"变量值(即environment.sh脚本中定义的)[root@k8s-master01 work]# kubectl -it exec dnsutils-ds-5sc4z bashroot@dnsutils-ds-5sc4z:/# cat /etc/resolv.confnamerver 10.254.0.2arch default.svc.cluster.local svc.cluster.local cluster.local localdomainoptions ndots:5[root@k8s-master01 work]# kubectl exec dnsutils-ds-5sc4z nslookup kubernetesrver: 10.254.0.2address: 10.254.0.2#53name: kubernetes.default.svc.cluster.localaddress: 10.254.0.1[root@k8s-master01 work]# kubectl exec dnsutils-ds-5sc4z nslookup www.baidu.comrver: 10.254.0.2address: 10.254.0.2#53non-authoritative answer:www.baidu.com canonical name = www.a.shifen.com.www.a.shifen.com canonical name = www.wshifen.com.name: www.wshifen.comaddress: 103.235.46.39发现可以将服务 my-nginx 解析到上面它对应的 cluster ip 10.254.170.246[root@k8s-master01 work]# kubectl exec dnsutils-ds-5sc4z nslookup my-nginxrver: 10.254.0.2address: 10.254.0.2#53non-authoritative answer:name: my-nginx.default.svc.cluster.localaddress: 10.254.170.246[root@k8s-master01 work]# kubectl exec dnsutils-ds-5sc4z nslookup kube-dns.kube-system.svc.clusterrver: 10.254.0.2address: 10.254.0.2#53** rver can't find kube-dns.kube-system.svc.cluster: nxdomaincommand terminated with exit code 1[root@k8s-master01 work]# kubectl exec dnsutils-ds-5sc4z nslookup kube-dns.kube-system.svcrver: 10.254.0.2address: 10.254.0.2#53name: kube-dns.kube-system.svc.cluster.localaddress: 10.254.0.2[root@k8s-master01 work]# kubectl exec dnsutils-ds-5sc4z nslookup kube-dns.kube-system.svc.cluster.localrver: 10.254.0.2address: 10.254.0.2#53name: kube-dns.kube-system.svc.cluster.localaddress: 10.254.0.2[root@k8s-master01 work]# kubectl exec dnsutils-ds-5sc4z nslookup kube-dns.kube-system.svc.cluster.local.rver: 10.254.0.2address: 10.254.0.2#53name: kube-dns.kube-system.svc.cluster.localaddress: 10.254.0.2
可以从微软中国提供的 gcr.io免费代理下载被墙的镜像;下面部署命令均在k8s-master01节点上执行。
1)修改配置文件将下载的 kubernetes-rver-linux-amd64.tar.gz 解压后,再解压其中的 kubernetes-src.tar.gz 文件 (上面在coredns部署阶段已经解压过了)[root@k8s-master01 ~]# cd /opt/k8s/work/kubernetes/[root@k8s-master01 kubernetes]# ls -d cluster/addons/dashboardcluster/addons/dashboarddashboard 对应的目录是:cluster/addons/dashboard[root@k8s-master01 kubernetes]# cd /opt/k8s/work/kubernetes/cluster/addons/dashboard修改 rvice 定义,指定端口类型为 nodeport,这样外界可以通过地址 nodeip:nodeport 访问 dashboard;[root@k8s-master01 dashboard]# vim dashboard-rvice.yamlapiversion: v1kind: rvicemetadata:name: kubernetes-dashboardnamespace: kube-systemlabels:k8s-app: kubernetes-dashboardkubernetes.io/cluster-rvice: "true"addonmanager.kubernetes.io/mode: reconcilespec:type: nodeport # 添加这一行内容lector:k8s-app: kubernetes-dashboardports:- port: 443targetport: 84432) 执行所有定义文件需要提前fq将k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1镜像下载下来,然后上传到node节点上,然后执行"docker load ......" 导入到node节点的images镜像里或者从微软中国提供的gcr.io免费代理下载被墙的镜像,然后在修改yaml文件里更新dashboard的镜像下载地址[root@k8s-master01 dashboard]# fgrep "image" ./*./dashboard-controller.yaml: image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1[root@k8s-master01 dashboard]# ls *.yamldashboard-configmap.yaml dashboard-controller.yaml dashboard-rbac.yaml dashboard-cret.yaml dashboard-rvice.yaml[root@k8s-master01 dashboard]# kubectl apply -f .3)查看分配的 nodeport[root@k8s-master01 dashboard]# kubectl get deployment kubernetes-dashboard -n kube-systemname ready up-to-date available agekubernetes-dashboard 1/1 1 1 48s[root@k8s-master01 dashboard]# kubectl --namespace kube-system get pods -o widename ready status restarts age ip node nominated node readiness gatescoredns-5b969f4c88-pd5js 1/1 running 0 33m 172.30.72.3 k8s-node03 <none> <none>kubernetes-dashboard-85bcf5dbf8-8s7hm 1/1 running 0 63s 172.30.72.6 k8s-node03 <none> <none>[root@k8s-master01 dashboard]# kubectl get rvices kubernetes-dashboard -n kube-systemname type cluster-ip external-ip port(s) agekubernetes-dashboard nodeport 10.254.164.208 <none> 443:30284/tcp 104s可以看出:nodeport 30284 映射到 dashboard pod 443 端口;4)查看 dashboard 支持的命令行参数[root@k8s-master01 dashboard]# kubectl exec --namespace kube-system -it kubernetes-dashboard-85bcf5dbf8-8s7hm -- /dashboard --help2019/06/25 16:54:04 starting overwatchusage of /dashboard:--alsologtostderr log to standard error as well as files--api-log-level string level of api request logging. should be one of 'info|none|debug'. default: 'info'. (default "info")--apirver-host string the address of the kubernetes apirver to connect to in the format of protocol://address:port, e.g., http://localhost:8080. if not specified, the assumption is that the binary runs inside a kubernetes cluster and local discovery is attempted.--authentication-mode strings enables authentication options that will be reflected on login screen. supported values: token, basic. default: token.note that basic option should only be ud if apirver has '--authorization-mode=abac' and '--basic-auth-file' flags t. (default [token])--auto-generate-certificates when t to true, dashboard will automatically generate certificates ud to rve https. default: fal.--bind-address ip the ip address on which to rve the --cure-port (t to 0.0.0.0 for all interfaces). (default 0.0.0.0)--default-cert-dir string directory path containing '--tls-cert-file' and '--tls-key-file' files. ud also when auto-generating certificates flag is t. (default "/certs")--disable-ttings-authorizer when enabled, dashboard ttings page will not require ur to be logged in and authorized to access ttings page.--enable-incure-login when enabled, dashboard login view will also be shown when dashboard is not rved over https. default: fal.--enable-skip-login when enabled, the skip button on the login page will be shown. default: fal.--heapster-host string the address of the heapster apirver to connect to in the format of protocol://address:port, e.g., http://localhost:8082. if not specified, the assumption is that the binary runs inside a kubernetes cluster and rvice proxy will be ud.--incure-bind-address ip the ip address on which to rve the --port (t to 0.0.0.0 for all interfaces). (default 127.0.0.1)--incure-port int the port to listen to for incoming http requests. (default 9090)--kubeconfig string path to kubeconfig file with authorization and master location information.--log_backtrace_at tracelocation when logging hits line file:n, emit a stack trace (default :0)--log_dir string if non-empty, write log files in this directory--logtostderr log to standard error instead of files--metric-client-check-period int time in conds that defines how often configured metric client health check should be run. default: 30 conds. (default 30)--port int the cure port to listen to for incoming https requests. (default 8443)--stderrthreshold verity logs at or above this threshold go to stderr (default 2)--system-banner string when non-empty displays message to dashboard urs. accepts simple html tags. default: ''.--system-banner-verity string verity of system banner. should be one of 'info|warning|error'. default: 'info'. (default "info")--tls-cert-file string file containing the default x509 certificate for https.--tls-key-file string file containing the default x509 private key matching --tls-cert-file.--token-ttl int expiration time (in conds) of jwe tokens generated by dashboard. default: 15 min. 0 - never expires (default 900)-v, --v level 信格式 log level for v logs--vmodule modulespec comma-parated list of pattern=n ttings for file-filtered loggingpflag: help requestedcommand terminated with exit code 25)访问dashboard从1.7版本开始,dashboard只允许通过https访问,如果使用kube proxy则必须监听localhost或127.0.0.1。对于nodeport没有这个限制,但是仅建议在开发环境中使用。对于不满足这些条件的登录访问,在登录成功后浏览器不跳转,始终停在登录界面。有三种访问dashboard的方式:-> kubernetes-dashboard 服务暴露了 nodeport,可以使用 https://nodeip:nodeport 地址访问 dashboard;-> 通过 kube-apirver 访问 dashboard;-> 通过 kubectl proxy 访问 dashboard:第一种方式:kubernetes-dashboard 服务暴露了nodeport端口,可以通过https://nodeip+nodeport 来访问dashboard[root@k8s-master01 dashboard]# kubectl get rvices kubernetes-dashboard -n kube-systemname type cluster-ip external-ip port(s) agekubernetes-dashboard nodeport 10.254.164.208 <none> 443:30284/tcp 14m则可以通过访问https://172.16.60.244:30284,https://172.16.60.245:30284,https://172.16.60.246:30284 来打开dashboard界面第二种方式:通过 kubectl proxy 访问 dashboard启动代理(下面命令会一直在前台执行,可以选择使用tmux虚拟终端执行)[root@k8s-master01 dashboard]# kubectl proxy --address='localhost' --port=8086 --accept-hosts='^*$'starting to rve on 127.0.0.1:8086需要注意:--address 必须为 localhost 或 127.0.0.1;需要指定 --accept-hosts 选项,否则浏览器访问 dashboard 页面时提示 “unauthorized”;这样就可以在这个服务器的浏览器里访问 url:http://127.0.0.1:8086/api/v1/namespaces/kube-system/rvices/https:kubernetes-dashboard:/proxy第三种方式:通过 kube-apirver 访问 dashboard获取集群服务地址列表:[root@k8s-master01 dashboard]# kubectl cluster-infokubernetes master is running at https://172.16.60.250:8443coredns is running at https://172.16.60.250:8443/api/v1/namespaces/kube-system/rvices/kube-dns:dns/proxykubernetes-dashboard is running at https://172.16.60.250:8443/api/v1/namespaces/kube-system/rvices/https:kubernetes-dashboard:/proxyto further debug and diagno cluster problems, u 'kubectl cluster-info dump'.需要注意:必须通过 kube-apirver 的安全端口(https)访问 dashbaord,访问时浏览器需要使用自定义证书,否则会被 kube-apirver 拒绝访问。创建和导入自定义证书的操作已经在前面"部署node工作节点"环节介绍过了,这里就略过了~~~浏览器访问 url:https://172.16.60.250:8443/api/v1/namespaces/kube-system/rvices/https:kubernetes-dashboard:/proxy 即可打开dashboard界面6)创建登录 dashboard 的 token 和 kubeconfig 配置文件dashboard 默认只支持 token 认证(不支持 client 证书认证),所以如果使用 kubeconfig 文件,需要将 token 写入到该文件。方法一:创建登录 token[root@k8s-master01 ~]# kubectl create sa dashboard-admin -n kube-systemrviceaccount/dashboard-admin created[root@k8s-master01 ~]# kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --rviceaccount=kube-system:dashboard-adminclusterrolebinding.rbac.authorization.k8s.io/dashboard-admin created[root@k8s-master01 ~]# admin_cret=$(kubectl get crets -n kube-system | grep dashboard-admin | awk '{print $1}')[root@k8s-master01 ~]# dashboard_login_token=$(kubectl describe cret -n kube-system ${admin_cret} | grep -e '^token' | awk '{print $2}')[root@k8s-master01 ~]# echo ${dashboard_login_token}eyjhbgcioijsuzi1niisimtpzci6iij9.eyjpc3mioijrdwjlcm5ldgvzl3nlcnzpy2vhy2nvdw50iiwia3vizxjuzxrlcy5pby9zzxj2awnlywnjb3vudc9uyw1lc3bhy2uioijrdwjllxn5c3rlbsisimt1ymvybmv0zxmuaw8vc2vydmljzwfjy291bnqvc2vjcmv0lm5hbwuioijkyxnoym9hcmqtywrtaw4tdg9rzw4tcmnicnmilcjrdwjlcm5ldgvzlmlvl3nlcnzpy2vhy2nvdw50l3nlcnzpy2utywnjb3vudc5uyw1lijoizgfzagjvyxjklwfkbwluiiwia3vizxjuzxrlcy5pby9zzxj2awnlywnjb3vudc9zzxj2awnllwfjy291bnqudwlkijoizgq1njg0ogutotc2yi0xmwu5ltkwzdqtmda1mdu2ywm3yzgxiiwic3viijoic3lzdgvtonnlcnzpy2vhy2nvdw50omt1ymutc3lzdgvtomrhc2hib2fyzc1hzg1pbij9.kwh_zhi-da8kifs7drmnecs_pcxq3b2ujs_eoor-gvoaz29cjtzd_z67brds1qlj8oyiqjw2_m837ekucpj8lriontmjwbpmebphhomdgdsmdj37uec7yqa5amkvvwiyiukgthjjglaklk6eh7ihvcez3ibhwtfxlulu24mlmt9xp4j7m5fig7i5-ctflibv2nsvwlwiv6jaecocbgx1w0fjtmn9llheidqp1byxu_wavsfywoypeqduqbqcz7iovt1zuvyfugs5rxzshm86tck_pteinyo1dgljmrlrz3tb1oaow8_u-vnhqsnwkjbzjnuljfzcgy1yoi2xub7v4w则可以使用上面输出的token 登录 dashboard。方法二:创建使用 token 的 kubeconfig 文件 (推荐使用这种方式)[root@k8s-master01 ~]# source /opt/k8s/bin/environment.sh设置集群参数[root@k8s-master01 ~]# kubectl config t-cluster kubernetes \--certificate-authority=/etc/kubernetes/cert/ca.pem \--embed-certs=true \--rver=${kube_apirver} \--kubeconfig=dashboard.kubeconfig设置客户端认证参数,使用上面创建的 token[root@k8s-master01 ~]# kubectl config t-credentials dashboard_ur \--token=${dashboard_login_token} \--kubeconfig=dashboard.kubeconfig设置上下文参数[root@k8s-master01 ~]# kubectl config t-context default \--cluster=kubernetes \--ur=dashboard_ur \--kubeconfig=dashboard.kubeconfig设置默认上下文[root@k8s-master01 ~]# kubectl config u-context default --kubeconfig=dashboard.kubeconfig将上面生成的 dashboard.kubeconfig文件拷贝到本地,然后使用这个文件登录 dashboard。[root@k8s-master01 ~]# ll dashboard.kubeconfig-rw------- 1 root root 3025 jun 26 01:14 dashboard.kubeconfig
metrics-rver 通过 kube-apirver 发现所有节点,然后调用 kubelet apis(通过 https 接口)获得各节点(node)和 pod 的 cpu、memory 等资源使用情况。从 kubernetes 1.12 开始,kubernetes 的安装脚本移除了 heapster,从 1.13 开始完全移除了对 heapster 的支持,heapster 不再被维护。替代方案二十四式简化太极拳音乐如下:
->用于支持自动扩缩容的 cpu/memory hpa metrics:metrics-rver;
->通用的监控方案:使用第三方可以获取 prometheus 格式监控指标的监控系统,如 prometheus operator;
->事件传输:使用第三方工具来传输、归档 kubernetes events;
从 kubernetes 1.8 开始,资源使用指标(如容器 cpu 和内存使用率)通过 metrics api 在 kubernetes 中获取, metrics-rver 替代了heapster。metrics rver 实现了resource metrics api,metrics rver是集群范围资源使用数据的聚合器。metrics rver 从每个节点上的 kubelet 公开的 summary api 中采集指标信息。
在了解metrics-rver之前,必须要事先了解下metrics api的概念。metrics api相比于之前的监控采集方式(hepaster)是一种新的思路,官方希望核心指标的监控应该是稳定的,版本可控的,且可以直接被用户访问(例如通过使用 kubectl top 命令),或由集群中的控制器使用(如hpa),和其他的kubernetes apis一样。官方废弃heapster项目,就是为了将核心资源监控作为一等公民对待,即像pod、rvice那样直接通过api-rver或者client直接访问,不再是安装一个hepater来汇聚且由heapster单独管理。
假设每个pod和node我们收集10个指标,从k8s的1.6开始,支持5000节点,每个节点30个pod,假设采集粒度为1分钟一次,则”10 x 5000 x 30 / 60 = 25000 平均每分钟2万多个采集指标”。因为k8s的api-rver将所有的数据持久化到了etcd中,显然k8s本身不能处理这种频率的采集,而且这种监控数据变化快且都是临时数据,因此需要有一个组件单独处理他们,k8s版本只存放部分在内存中,于是metric-rver的概念诞生了。其实hepaster已经有暴露了api,但是用户和kubernetes的其他组件必须通过master proxy的方式才能访问到,且heapster的接口不像api-rver一样,有完整的鉴权以及client集成。
有了metrics rver组件,也采集到了该有的数据,也暴露了api,但因为api要统一,如何将请求到api-rver的/apis/metrics请求转发给metrics rver呢,
解决方案就是:kube-aggregator,在k8s的1.7中已经完成,之前metrics rver一直没有面世,就是耽误在了kube-aggregator这一步。
->provide an api for registering api rvers;
->summarize discovery information from all the rvers;
->proxy client requests to individual rvers;
->metrics api 只可以查询当前的度量数据,并不保存历史数据
->metrics api uri 为 /apis/metrics.k8s.io/,在 k8s.io/metrics 维护
->必须部署 metrics-rver 才能使用该 api,metrics-rver 通过调用 kubelet summary api 获取数据
metrics rver定时从kubelet的summary api(类似/ap1/v1/nodes/nodename/stats/summary)采集指标信息,这些聚合过的数据将存储在内存中,且以metric-api的形式暴露出去。metrics rver复用了api-rver的库来实现自己的功能,比如鉴权、版本等,为了实现将数据存放在内存中吗,去掉了默认的etcd存储,引入了内存存储(即实现storage interface)。因为存放在内存中,因此监控数据是没有持久化的,可以通过第三方存储来拓展,这个和heapster是一致的。
kubernetes dashboard 还不支持 metrics-rver,如果使用 metrics-rver 替代 heapster,将无法在 dashboard 中以图形展示 pod 的内存和 cpu 情况,需要通过 prometheus、grafana 等监控方案来弥补。kuberntes 自带插件的 manifests yaml 文件使用 gcr.io 的 docker registry,国内被墙,需要手动替换为其它 registry 地址(本文档未替换);可以从微软中国提供的 gcr.io 免费代理下载被墙的镜像;下面部署命令均在k8s-master01节点上执行。
1)安装 metrics-rver从 github clone 源码:[root@k8s-master01 ~]# cd /opt/k8s/work/[root@k8s-master01 work]# git clone https://github.com/kubernetes-incubator/metrics-rver.git[root@k8s-master01 work]# cd metrics-rver/deploy/1.8+/[root@k8s-master01 1.8+]# lsaggregated-metrics-reader.yaml auth-reader.yaml metrics-rver-deployment.yaml resource-reader.yamlauth-delegator.yaml metrics-apirvice.yaml metrics-rver-rvice.yaml修改 metrics-rver-deployment.yaml 文件,为 metrics-rver 添加三个命令行参数(在"imagepullpolicy"行的下面添加):[root@k8s-master01 1.8+]# cp metrics-rver-deployment.yaml metrics-rver-deployment.yaml.bak[root@k8s-master01 1.8+]# vim metrics-rver-deployment.yaml.........args:- --metric-resolution=30s- --kubelet-preferred-address-types=internalip,hostname,internaldns,externaldns,externalip这里需要注意:--metric-resolution=30s:从 kubelet 采集数据的周期;--kubelet-preferred-address-types:优先使用 internalip 来访问 kubelet,这样可以避免节点名称没有 dns 解析记录时,通过节点名称调用节点 kubelet api 失败的情况(未配置时默认的情况);另外:需要提前fq将k8s.gcr.io/metrics-rver-amd64:v0.3.3镜像下载下来,然后上传到node节点上,然后执行"docker load ......" 导入到node节点的images镜像里或者从微软中国提供的gcr.io免费代理下载被墙的镜像,然后在修改yaml文件里更新dashboard的镜像下载地址.[root@k8s-master01 1.8+]# fgrep "image" metrics-rver-deployment.yaml# mount in tmp so we can safely u from-scratch images and/or read-only containersimage: k8s.gcr.io/metrics-rver-amd64:v0.3.3imagepullpolicy: always由于已经提前将相应镜像导入到各node节点的image里了,所以需要将metrics-rver-deployment.yaml文件中的镜像拉取策略修改为"ifnotprent".即:本地有则使用本地镜像,不拉取[root@k8s-master01 1.8+]# fgrep "image" metrics-rver-deployment.yaml# mount in tmp so we can safely u from-scratch images and/or read-only containersimage: k8s.gcr.io/metrics-rver-amd64:v0.3.3imagepullpolicy: ifnotprent部署 metrics-rver:[root@k8s-master01 1.8+]# kubectl create -f .2)查看运行情况[root@k8s-master01 1.8+]# kubectl -n kube-system get pods -l k8s-app=metrics-rvername ready status restarts agemetrics-rver-54997795d9-4cv6h 1/1 running 0 50s[root@k8s-master01 1.8+]# kubectl get svc -n kube-system metrics-rvername type cluster-ip external-ip port(s) agemetrics-rver clusterip 10.254.238.208 <none> 443/tcp 65s3)metrics-rver 的命令行参数 (在任意一个node节点上执行下面命令)[root@k8s-node01 ~]# docker run -it --rm k8s.gcr.io/metrics-rver-amd64:v0.3.3 --help4)查看 metrics-rver 输出的 metrics-> 通过 kube-apirver 或 kubectl proxy 访问:https://172.16.60.250:8443/apis/metrics.k8s.io/v1beta1/nodeshttps://172.16.60.250:8443/apis/metrics.k8s.io/v1beta1/nodes/https://172.16.60.250:8443/apis/metrics.k8s.io/v1beta1/podshttps://172.16.60.250:8443/apis/metrics.k8s.io/v1脚底痛是什么原因beta1/namespace//pods/-> 直接使用 kubectl 命令访问 :# kubectl get --raw apis/metrics.k8s.io/v1beta1/nodes# kubectl get --raw apis/metrics.k8s.io/v1beta1/pods kubectl# get --raw apis/metrics.k8s.io/v1beta1/nodes/ kubectl# get --raw apis/metrics.k8s.io/v1beta1/namespace//pods/[root@k8s-master01 1.8+]# kubectl get --raw "/apis/metrics.k8s.io/v1beta1" | jq .{"kind": "apiresourcelist","apiversion": "v1","groupversion": "metrics.k8s.io/v1beta1","resources": [{"name": "nodes","singularname": "","namespaced": fal,"kind": "nodemetrics","verbs": ["get","list"]},{"name": "pods","singularname": "","namespaced": true,"kind": "podmetrics","verbs": ["get","list"]}]}[root@k8s-master01 1.8+]# kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes" | jq .{"kind": "nodemetricslist","apiversion": "metrics.k8s.io/v1beta1","metadata": {"lflink": "/apis/metrics.k8s.io/v1beta1/nodes"},"items": [{"metadata": {"name": "k8s-node01","lflink": "/apis/metrics.k8s.io/v1beta1/nodes/k8s-node01","creationtimestamp": "2019-06-27t17:11:43z"},"timestamp": "2019-06-27t17:11:36z","window": "30s","usage": {"cpu": "47615396n","memory": "2413536ki"}},{"metadata": {"name": "k8s-node02","lflink": "/apis/metrics.k8s.io/v1beta1/nodes/k8s-node02","creationtimestamp": "2019-06-27t17:11:43z"},"timestamp": "2019-06-27t17:11:38z","window": "30s","usage": {"cpu": "42000411n","memory": "2496152ki"}},{"metadata": {"name": "k8s-node03","lflink": "/apis/metrics.k8s.io/v1beta1/nodes/k8s-node03","creationtimestamp": "2019-06-27t17:11:43z"},"timestamp": "2019-06-27t17:11:40z","window": "30s","usage": {"cpu": "54095172n","memory": "3837404ki"}}]}这里需要注意:/apis/metrics.k8s.io/v1beta1/nodes 和 /apis/metrics.k8s.io/v1beta1/pods 返回的 usage 包含 cpu 和 memory;5)使用 kubectl top 命令查看集群节点资源使用情况[root@k8s-master01 1.8+]# kubectl top nodename cpu(cores) cpu% memory(bytes) memory% k8s-node01 45m 1% 2357mi 61% k8s-node02 44m 1% 2437mi 63% k8s-node03 54m 1% 3747mi 47%=======================================================================================================================================报错解决:[root@k8s-master01 1.8+]# kubectl top nodeerror from rver (forbidden): nodes.metrics.k8s.io is forbidden: ur "aggregator" cannot list resource "nodes" in api group "metrics.k8s.io" at the cluster scope出现上述错误的原因主要是未对aggregator这个sa进行rbac授权!偷懒的解决方案,直接将这个sa和cluster-admin进行绑定,但不符合最小权限原则。[root@k8s-master01 1.8+]# kubectl create clusterrolebinding custom-metric-with-cluster-admin --clusterrole=cluster-admin --ur=aggregator
上面已经部署了metric-rver,几乎容器运行的大多数指标数据都能采集到了,但是下面这种情况的指标数据的采集却无能为力:
->调度了多少个replicas?现在可用的有几个?
->多少个pod是running/stopped/terminated状态?
->pod重启了多少次?
->当前有多少job在运行中?
这些则是kube-state-metrics提供的内容,它是k8s的一个附加服务,基于client-go开发的。它会轮询kubernetes api,并将kubernetes的结构化信息转换为metrics。kube-state-metrics能够采集绝大多数k8s内置资源的相关数据,例如pod、deploy、rvice等等。同时它也提供自己的数据,主要是资源采集个数和采集发生的异常次数统计。
cronjob metrics
daemont metrics
deployment metrics
job metrics
limitrange metrics
node metrics
persistentvolume metrics
persistentvolumeclaim metrics
pod metrics
pod disruption budget metrics
replicat metrics
replicationcontroller metrics
resourcequota metrics
rvice metrics
statefult metrics
namespace metrics
horizontal pod autoscaler metrics
endpoint metrics
cret metrics
configmap metrics
kube_pod_info
kube_pod_owner
kube_pod_status_running
kube_pod_status_ready
kube_pod_status_scheduled
kube_pod_container_status_waiting
kube_pod_container_status_terminated_reason
…………..
1)metric-rver是从api-rver中获取cpu,内存使用率这种监控指标,并把它们发送给存储后端,如influxdb或云厂商,它当前的核心作用是:为hpa等组件提供决策指标支持。
2)kube-state-metrics关注于获取k8s各种资源的最新状态,如deployment或者daemont,之所以没有把kube-state-metrics纳入到metric-rver的能力中,是因为它们的关注点本质上是不一样的。metric-rver仅仅是获取、格式化现有数据,写入特定的存储,实质上是一个监控系统。而kube-state-metrics是将k8s的运行状况在内存中做了个快照,并且获取新的指标,但它没有能力导出这些指标
3)换个角度讲,kube-state-metrics本身是metric-rver的一种数据来源,虽然现在没有这么做。
4)另外,像prometheus这种监控系统,并不会去用metric-rver中的数据,它都是自己做指标收集、集成的(prometheus包含了metric-rver的能力),但prometheus可以监控metric-rver本身组件的监控状态并适时报警,这里的监控就可以通过kube-state-metrics来实现,如metric-rverpod的运行状态。
kube-state-metrics在之前的版本中暴露出两个问题:
1)/metrics接口响应慢(10-20s)
2)内存消耗太大,导致超出limit被杀掉
问题一的方案:就是基于client-go的cache tool实现本地缓存,具体结构为:var cache = map[uuid][]byte{}
问题二的的方案是:对于时间序列的字符串,是存在很多重复字符的(如namespace等前缀筛选),可以用指针或者结构化这些重复字符。
1)因为kube-state-metrics是监听资源的add、delete、update事件,那么在kube-state-metrics部署之前已经运行的资源的数据是不是就拿不到了?其实kube-state-metric利用client-go可以初始化所有已经存在的资源对象,确保没有任何遗漏;
2)kube-state-metrics当前不会输出metadata信息(如help和description);
3)缓存实现是基于golang的map,解决并发读问题当期是用了一个简单的互斥锁,应该可以解决问题,后续会考虑golang的sync.map安全map;
4)kube-state-metrics通过比较resource version来保证event的顺序;
5)kube-state-metrics并不保证包含所有资源;
下面部署命令均在k8s-master01节点上执行。
1)修改配置文件将下载的 kube-state-metrics.tar.gz 放到/opt/k8s/work目录下解压[root@k8s-master01 ~]# cd /opt/k8s/work/[root@k8s-master01 work]# tar -zvxf kube-state-metrics.tar.gz[root@k8s-master01 work]# cd kube-state-metricskube-state-metrics目录下,有所需要的文件[root@k8s-master01 kube-state-metrics]# lltotal 32-rw-rw-r-- 1 root root 362 may 6 17:31 kube-state-metrics-cluster-role-binding.yaml-rw-rw-r-- 1 root root 1076 may 6 17:31 kube-state-metrics-cluster-role.yaml-rw-rw-r-- 1 root root 1657 jul 1 17:35 kube-state-metrics-deployment.yaml-rw-rw-r-- 1 root root 381 may 6 17:31 kube-state-metrics-role-binding.yaml-rw-rw-r-- 1 root root 508 may 6 17:31 kube-state-metrics-role.yaml-rw-rw-r-- 1 root root 98 may 6 17:31 kube-state-metrics-rvice-account.yaml-rw-rw-r-- 1 root root 404 may 6 17:31 kube-state-metrics-rvice.yaml[root@k8s-master01 kube-state-metrics]# fgrep -r "image" ./*./kube-state-metrics-deployment.yaml: image: quay.io/coreos/kube-state-metrics:v1.5.0./kube-state-metrics-deployment.yaml: imagepullpolicy: ifnotprent./kube-state-metrics-deployment.yaml: image: k8s.gcr.io/addon-resizer:1.8.3./kube-state-metrics-deployment.yaml: imagepullpolicy: ifnotprent[root@k8s-master01 kube-state-metrics]# cat kube-state-metrics-rvice.yamlapiversion: v1kind: rvicemetadata:name: kube-函数零点的求法state-metricsnamespace: kube-systemlabels:k8s-app: kube-state-metricsannotations:prometheus.io/scrape: 'true'spec:ports:- name: http-metricsport: 8080targetport: http-metricsprotocol: tcp- name: telemetryport: 8081targetport: telemetryprotocol: tcptype: nodeport #添加这一行lector:k8s-app: kube-state-metrics注意两点:其中有个是镜像是"k8s.gcr.io/addon-resizer:1.8.3"在国内因为某些原因无法拉取,可以更换为"ist0ne/addon-resizer"即可正常使用。或者通过fq下载。rvice 如果需要集群外部访问,需要改为nodeport2)执行所有定义文件需要提前fq将quay.io/coreos/kube-state-metrics:v1.5.0 和 k8s.gcr.io/addon-resizer:1.8.3镜像下载下来,然后上传到node节点上,然后执行"docker load ......" 导入到node节点的images镜像里或者从微软中国提供的gcr.io免费代理下载被墙的镜像,然后在修改yaml文件里更新dashboard的镜像下载地址。由于已经提前将相应镜像导入到各node节点的image里了,所以需要将kube-state-metrics-deployment.yaml文件中的镜像拉取策略修改为"ifnotprent".即本地有则使用本地镜像,不拉取。[root@k8s-master01 kube-state-metrics]# kubectl create -f .执行后检查一下:[root@k8s-master01 kube-state-metrics]# kubectl get pod -n kube-system|grep kube-state-metrics kube-state-metrics-5dd55c764d-nnsdv 2/2 running 0 9m3s[root@k8s-master01 kube-state-metrics]# kubectl get svc -n kube-system|grep kube-state-metrics kube-state-metrics nodeport 10.254.228.212 <none> 8080:30978/tcp,8081:30872/tcp 9m14s[root@k8s-master01 kube-state-metrics]# kubectl get pod,svc -n kube-system|grep kube-state-metricspod/kube-state-metrics-5dd55c764d-nnsdv 2/2 running 0 9m12srvice/kube-state-metrics nodeport 10.254.228.212 <none> 8080:30978/tcp,8081:30872/tcp 9m18s3)验证kube-state-metrics数据采集通过上面的检查,可以得知映射到外部访问的nodeport端口是30978,通过任意一个node工作节点即可验证访问:[root@k8s-master01 kube-state-metrics]# curl http://172.16.60.244:30978/metrics|head -10% total % received % xferd average speed time time time currentdload upload total spent left speed0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0# help kube_configmap_info information about configmap.# type kube_configmap_info gaugekube_configmap_info{namespace="kube-system",configmap="extension-apirver-authentication"} 1kube_configmap_info{namespace="kube-system",configmap="coredns"} 1kube_configmap_info{namespace="kube-system",configmap="kubernetes-dashboard-ttings"} 1# help kube_configmap_created unix creation timestamp# type kube_configmap_created gaugekube_configmap_created{namespace="kube-system",configmap="extension-apirver-authentication"} 1.560825764e+09kube_configmap_created{namespace="kube-system",configmap="coredns"} 1.561479528e+09kube_configmap_created{namespace="kube-system",configmap="kubernetes-dashboard-ttings"} 1.56148146e+09100 73353 0 73353 0 0 9.8m 0 --:--:-- --:--:-- --:--:-- 11.6mcurl: (23) failed writing body (0 != 2048)
安装的话,可以参考docker私有仓库harbor介绍和部署方法详解,需要在两台节点机172.16.60.247、172.16.60.248上都安装harbor私有仓库环境。上层通过nginx+keepalived实现harbor的负载均衡+高可用,两个harbor相互同步(主主复制)。
1)”仓库管理”创建目标,创建后可以测试是否正常连接目标。
2)”同步管理”创建规则,在规则中调用上面创建的目标。
3)手动同步或定时同步。
例如:已经在172.16.60.247这台harbor节点的私有仓库library和kevin_img的项目里各自存放了镜像,如下:
现在要把172.16.60.247的harbor私有仓库的这两个项目下的镜像同步到另一个节点172.16.60.248的harbor里。同步同步方式:147 -> 148或147 <- 148
上面是手动同步,也可以选择定时同步,分别填写的是”秒 分 时 日 月 周“, 如下每两分钟同步一次! 则过了两分钟之后就会自动同步过来了~
[root@k8s-master01 ~]# kubectl get csname status message errorscheduler healthy ok controller-manager healthy ok etcd-2 healthy {"health":"true"} etcd-0 healthy {"health":"true"} etcd-1 healthy {"health":"true"} [root@k8s-master01 ~]# kubectl get nodesname status roles age versionk8s-node01 ready <none> 20d v1.14.2k8s-node02 ready <none> 20d v1.14.2k8s-node03 ready <none> 20d v1.14.2部署测试实例[root@k8s-master01 ~]# kubectl run kevin-nginx --image=nginx --replicas=3kubectl run --generator=deployment/apps.v1 is deprecated and will be removed in a future version. u kubectl run --generator=run-pod/v1 or kubectl create instead.deployment.apps/kevin-nginx created[root@k8s-master01 ~]# kubectl run --generator=run-pod/v1 kevin-nginx --image=nginx --replicas=3pod/kevin-nginx created稍等一会儿,查看创建的kevin-nginx的pod(由于创建时要自动下载nginx镜像,所以需要等待一段时间)[root@k8s-master01 ~]# kubectl get pods --all-namespaces|grep "kevin-nginx"default kevin-nginx 1/1 running 0 98sdefault kevin-nginx-569dcd559b-6h4nn 1/1 running 0 106sdefault kevin-nginx-569dcd559b-7f2b4 1/1 running 0 106sdefault kevin-nginx-569dcd559b-7tds2 1/1 running 0 106s查看具体详细事件[root@k8s-master01 ~]# kubectl get pods --all-namespaces -o wide|grep "kevin-nginx"default kevin-nginx 1/1 running 0 2m13s 172.30.72.12 k8s-node03 <none> <none>default kevin-nginx-569dcd559b-6h4nn 1/1 running 0 2m21s 172.30.56.7 k8s-node02 <none> <none>default kevin-nginx-569dcd559b-7f2b4 1/1 running 0 2m21s 172.30.72.11 k8s-node03 <none> <none>default kevin-nginx-569dcd559b-7tds2 1/1 running 0 2m21s 172.30.88.8 k8s-node01 <none> <none>[root@k8s-master01 ~]# kubectl get deployment|grep kevin-nginxkevin-nginx 3/3 3 3 2m57s创建svc[root@k8s-master01 ~]# kubectl expo deployment kevin-nginx --port=8080 --target-port=80 --type=nodeport[root@k8s-master01 ~]# kubectl get svc|grep kevin-nginxnginx nodeport 10.254.111.50 <none> 8080:32177/tcp 33s集群内部,各pod之间访问kevin-nginx[root@k8s-master01 ~]# curl http://10.254.111.50:8080外部访问kevin-nginx的地址为http://node_ip/32177http://172.16.60.244:32177http://172.16.60.245:32177http://172.16.60.246:32177
停相关进程:[root@k8s-node01 ~]# systemctl stop kubelet kube-proxy flanneld docker kube-proxy kube-nginx清理文件:[root@k8s-node01 ~]# source /opt/k8s/bin/environment.shumount kubelet 和 docker 挂载的目录[root@k8s-node01 ~]# mount | grep "${k8s_dir}" | awk '{print $3}'|xargs sudo umount删除 kubelet 工作目录[root@k8s-node01 ~]# sudo rm -rf ${k8s_dir}/kubelet删除 docker 工作目录[root@k8s-node01 ~]# sudo rm -rf ${docker_dir}删除 flanneld 写入的网络配置文件[root@k8s-node01 ~]# sudo rm -rf /var/run/flannel/删除 docker 的一些运行文件[root@k8s-node01 ~]# sudo rm -rf /var/run/docker/删除 systemd unit 文件[root@k8s-node01 ~]# sudo rm -rf /etc/systemd/system/{kubelet,docker,flanneld,kube-nginx}.rvice删除程序文件[root@k8s-node01 ~]# sudo rm -rf /opt/k8s/bin/*删除证书文件[root@k8s-node01 ~]# sudo rm -rf /etc/flanneld/cert /etc/kubernetes/cert清理 kube-proxy 和 docker 创建的 iptables[root@k8s-node01 ~]# iptables -f && sudo iptables -x && sudo iptables -f -t nat && sudo iptables -x -t nat删除 flanneld 和 docker 创建的网桥:[root@k8s-node01 ~]# ip link del flannel.1[root@k8s-node01 ~]# ip link del docker0
停相关进程:[root@k8s-master01 ~]# systemctl stop kube-apirver kube-controller-manager kube-scheduler kube-nginx清理文件:删除 systemd unit 文件[root@k8s-master01 ~]# rm -rf /etc/systemd/system/{kube-apirver,kube-controller-manager,kube-scheduler,kube-nginx}.rvice删除程序文件[root@k8s-master01 ~]# rm -rf /opt/k8s/bin/{kube-apirver,kube-controller-manager,kube-scheduler}删除证书文件[root@k8s-master01 ~]# rm -rf /etc/flanneld/cert /etc/kubernetes/cert清理 etcd 集群[root@k8s-master01 ~]# systemctl stop etcd清理文件:[root@k8s-master01 ~]# source /opt/k8s/bin/environment.sh删除 etcd 的工作目录和数据目录[root@k8s-master01 ~]# rm -rf ${etcd_data_dir} ${etcd_wal_dir}删除 systemd unit 文件[root@k8s-master01 ~]# rm -rf /etc/systemd/system/etcd.rvice删除程序文件[root@k8s-master01 ~]# rm -rf /opt/k8s/bin/etcd删除 x509 证书文件[root@k8s-master01 ~]# rm -rf /etc/etcd/cert/*
上面部署的dashboard是https证书方式,如果是http方式访问的kubernetes集群web-ui,操作如下:
1)配置kubernetes-dashboard.yaml (里面的"k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1"镜像已经提前在node节点上下载了)[root@k8s-master01 ~]# cd /opt/k8s/work/[root@k8s-master01 work]# cat kubernetes-dashboard.yaml# ------------------- dashboard cret ------------------- #apiversion: v1kind: cretmetadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboard-certsnamespace: kube-systemtype: opaque---# ------------------- dashboard rvice account ------------------- #apiversion: v1kind: rviceaccountmetadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kube-system---# ------------------- dashboard role & role binding ------------------- #kind: roleapiversion: rbac.authorization.k8s.io/v1metadata:name: kubernetes-dashboard-minimalnamespace: kube-systemrules:# allow dashboard to create 'kubernetes-dashboard-key-holder' cret.- apigroups: [""]resources: ["crets"]verbs: ["create"]# allow dashboard to create 'kubernetes-dashboard-ttings' config map.- apigroups: [""]resources: ["configmaps"]verbs: ["create"]# allow dashboard to get, update and delete dashboard exclusive crets.- apigroups: [""]resources: ["crets"]resourcenames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]verbs: ["get", "update", "delete"]# allow dashboard to get and update 'kubernetes-dashboard-ttings' config map.- apigroups: [""]resources: ["configmaps"]resourcenames: ["kubernetes-dashboard-ttings"]verbs: ["get", "update"]# allow dashboard to get metrics from heapster.- apigroups: [""]resources: ["rvices"]resourcenames: ["heapster"]verbs: ["proxy"]- apigroups: [""]resources: ["rvices/proxy"]resourcenames: ["heapster", "http:heapster:", "https:heapster:"]verbs: ["get"]---apiversion: rbac.authorization.k8s.io/v1kind: rolebindingmetadata:name: kubernetes-dashboard-minimalnamespace: kube-systemroleref:apigroup: rbac.authorization.k8s.iokind: rolename: kubernetes-dashboard-minimalsubjects:- kind: rviceaccountname: kubernetes-dashboardnamespace: kube-system---kind: clusterrolebindingapiversion: rbac.authorization.k8s.io/v1beta1metadata:name: kubernetes-dashboardsubjects:- kind: rviceaccountname: kubernetes-dashboardnamespace: kube-systemroleref:kind: clusterrolename: cluster-adminapigroup: rbac.authorization.k8s.io---# ------------------- dashboard deployment ------------------- #kind: deploymentapiversion: apps/v1beta2metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kube-systemspec:replicas: 1revisionhistorylimit: 10lector:matchlabels:k8s-app: kubernetes-dashboardtemplate:metadata:labels:k8s-app: kubernetes-dashboardspec:rviceaccountname: kubernetes-dashboard-admincontainers:- name: kubernetes-dashboardimage: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1ports:- containerport: 9090protocol: tcpargs:#- --auto-generate-certificates# uncomment the following line to manually specify kubernetes api rver host# if not specified, dashboard will attempt to auto discover the api rver and connect# to it. uncomment only if the default does not work.#- --apirver-host=http://10.0.1.168:8080volumemounts:- name: kubernetes-dashboard-certsmountpath: /certs# create on-disk volume to store exec logs- mountpath: /tmpname: tmp-volumelivenessprobe:httpget:scheme: httppath: /port: 9090initialdelayconds: 30timeoutconds: 30volumes:- name: kubernetes-dashboard-certscret:cretname: kubernetes-dashboard-certs- name: tmp-volumeemptydir: {}rviceaccountname: kubernetes-dashboard# comment the following toleratio党支部半年总结ns if dashboard must not be deployed on mastertolerations:- key: node-role.kubernetes.io/mastereffect: noschedule---# ------------------- dashboard rvice ------------------- #kind: rviceapiversion: v1metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kube-systemspec:ports:- port: 9090targetport: 9090lector:k8s-app: kubernetes-dashboard# ------------------------------------------------------------kind: rviceapiversion: v1metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboard-externalnamespace: kube-systemspec:ports:- port: 9090targetport: 9090nodeport: 30090type: nodeportlector:k8s-app: kubernetes-dashboard创建这个yaml文件[root@k8s-master01 work]# kubectl create -f kubernetes-dashboard.yaml稍微等一会儿,查看kubernetes-dashboard的pod创建情况(如下可知,该pod落在了k8s-node03节点上,即172.16.60.246)[root@k8s-master01 work]# kubectl get pods -n kube-system -o wide|grep "kubernetes-dashboard"kubernetes-dashboard-7976c5cb9c-q7z2w 1/1 running 0 10m 172.30.72.6 k8s-node03 <none> <none>[root@k8s-master01 work]# kubectl get svc -n kube-system|grep "kubernetes-dashboard"kubernetes-dashboard-external nodeport 10.254.227.142 <none> 9090:30090/tcp 10m
本文发布于:2023-04-04 20:18:28,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/6afd27e93123f60812856d99116ab010.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Kubernetes(K8S)容器集群管理环境完整部署详细教程.doc
本文 PDF 下载地址:Kubernetes(K8S)容器集群管理环境完整部署详细教程.pdf
留言与评论(共有 0 条评论) |