云加社区

避坑指南!如何在TKE上安装KubeSphere?


导语 | 本文推选自腾讯云开发者社区-【技思广益 · 腾讯技术人原创集】专栏。该专栏是腾讯云开发者社区为腾讯技术人与广泛开发者打造的分享交流窗口。栏目邀约腾讯技术人分享原创的技术积淀,与广泛开发者互启迪共成长。 本文作者是腾讯云原生架构 师imroc 。

本文 主要介绍在腾讯云容器服务上如何安装KubeSphere及其踩坑与注意事项,希望可以给对此方面感兴趣的开发者们一些经验和帮助。


安装步骤


具体安装步骤参考KubeSphere官方文档: 在腾讯云TKE安装 KubeSphere 。

链接: https://kubesphere.io/zh/docs/installing-on-kubernetes/hosted-kubernetes/install-ks-on-tencent-tke/

踩坑与注意事项


(一)cbs磁盘容量以10Gi为倍数


腾讯云容器服务默认使用CBS云硬盘作为存储,容量只支持10Gi的倍数,如果定义pvc时指定的容量不是10Gi的倍数,就会挂盘失败。
安装KubeSphere时,修改下ClusterConfiguration中各个组件的volumeSize配置,确保是10Gi的倍数。

(二)卸载卡住与卸载不干净导致重装失败


有时安装出问题,希望卸载重装,使用KubeSphere官方文档 从 Kubernetes上卸载KubeSphere 中的kubesphere-delete.sh脚本进行清理,可能会出现卡住的情况。

通常是有finalizer的原因:


编辑资源删除相应finalizer即可。
如果清理不干净,重装还会报错:

通常是关联的一些MutatingWebhookConfiguration,ValidatingWebhookConfiguration,ClusterRole, ClusterRoleBinding等资源没清理,可以根据ks-installer日志定位并清理。

(三)监控不兼容导致看不到超级节点中Pod的监控


KubeSphere部署完后看工作负载的Pod列表,没有超级节点上Pod的监控数据:


是因为KubeSphere启用的监控,采集cadvisor监控数据的采集规则是,访问所有节点的10250端口去拉监控数据,而超级节点的IP是个无法路由的“假”IP,所以拉不到数据。

解决方案:按照以下步骤增加自定义采集规则 。


  • 准备secret yaml scrape-config.yaml:

apiVersion: v1kind: Secrettype: Opaquemetadata:  name: additional-scrape-configs  namespace: kubesphere-monitoring-systemstringData:  additional-scrape-configs.yaml: |-    - job_name: kubelet # eks cadvisor 监控,为兼容 ks 查询,固定 job 名为 kubelet      honor_timestamps: true      metrics_path: '/metrics'      params:        collect[]:        - 'ipvs'      scheme: http      kubernetes_sd_configs:      - role: pod      relabel_configs:      - source_labels: [__meta_kubernetes_pod_annotation_tke_cloud_tencent_com_pod_type]        regex: eklet        action: keep      - source_labels: [__meta_kubernetes_pod_phase]        regex: Running        action: keep      - source_labels: [__meta_kubernetes_pod_ip]        separator: ;        regex: (.*)        target_label: __address__        replacement: ${1}:9100        action: replace      - source_labels: [__meta_kubernetes_pod_name]        separator: ;        regex: (.*)        target_label: pod        replacement: ${1}        action: replace      - source_labels: [__meta_kubernetes_namespace]        separator: ;        regex: (.*)        target_label: namespace        replacement: ${1}        action: replace      metric_relabel_configs:      - source_labels: [__name__]        separator: ;        regex: container_.*        replacement: $1        action: keep      - target_label: metrics_path        replacement: /metrics/cadvisor        action: replace    - job_name: eks # eks cadvisor 之外的其它监控      honor_timestamps: true      metrics_path: '/metrics'      params:        collect[]:        - 'ipvs'      scheme: http      kubernetes_sd_configs:      - role: pod      relabel_configs:      - source_labels: [__meta_kubernetes_pod_annotation_tke_cloud_tencent_com_pod_type]        regex: eklet        action: keep      - source_labels: [__meta_kubernetes_pod_phase]        regex: Running        action: keep      - source_labels: [__meta_kubernetes_pod_ip]        separator: ;        regex: (.*)        target_label: __address__        replacement: ${1}:9100        action: replace      - source_labels: [__meta_kubernetes_pod_name]        separator: ;        regex: (.*)        target_label: pod        replacement: ${1}        action: replace      - source_labels: [__meta_kubernetes_namespace]        separator: ;        regex: (.*)        target_label: namespace        replacement: ${1}        action: replace      metric_relabel_configs:      - source_labels: [__name__]        separator: ;        regex: (container_.*|pod_.*|kubelet_.*)        replacement: $1        action: keep

  • 创建secret:

kubectl apply -f scrape-config.yaml

  • 修改Prometheus CR:

kubectl -n kubesphere-monitoring-system edit prometheuses.monitoring.coreos.com k8s

加入additionalScrapeConfigs:
spec:  additionalScrapeConfigs:    key: additional-scrape-configs.yaml    name: additional-scrape-configs

s-apiserver出现crash



一般是kubesphere的chart包不完善,crd没装完整,可以手动装一下:
kubectl apply -f https://raw.githubusercontent.com/kubesphere/notification-manager/master/config/bundle.yaml

参考 : https://kubesphere.com.cn/forum/d/7610-ks-330-ks-apiserver-crash/3



作者简介
imroc
腾讯云开发者社区【技思广益·腾讯技术人原创集】作者

腾讯云原生架构师,负责腾讯云原生产品解决方案与售后的技术支持,根据客户需求输出合理技术方案与最佳实践,为客户业务保驾护航。



推荐阅读
一种海量数据安全分类分级架构的实现!
一站式DevOps真的能提速增效吗?TVP吐槽大会邀您来验证!
玩转腾讯云!手把手教你用RunInstances接口创建CVM时给公网IP和弹性网卡打标签
《云安全最佳实践-创作者计划》参与征文抢千元好礼!

9 月 24 日 , CODING DevOps 专题 TVP 吐槽大会火爆开启 ,一同见证领域大咖巅峰对决!

扫码立即参会赢好礼👇



👇 点击 「阅读原文」 , 注册成为社 区创作者,认识大咖,打造你的技术影响力!