k8s kubelet 10250监控端口访问配置

一、修改kubelet的config.yaml文件

修改成:

二、找到证书<本文使用的pem证书>

三、测试

curl -k --cert /etc/kubernetes/pki/ca.pem --key /etc/kubernetes/pki/ca-key.pem https://192.168.4.24:10250/pods

curl -k --cert /etc/kubernetes/pki/ca.pem --key /etc/kubernetes/pki/ca-key.pem https://192.168.4.24:10250/metrics

五、prometheus配置

5.1 metrics配置

5.2 pem文件转crt

pem转pem编码CRT,保留abse64格式

openssl x509 -in ca.pem -out ca.crt

pem转DER编码CRT(二进制格式),若目标系统要求crt文件为二进制DER格式:

openssl x509 -outform der -in ca.pem -out ca.crt

5.3 token生成

复制代码
创建ServiceAccount和RABC

# prometheus-rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus
  namespace: monitoring
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: prometheus
rules:
- apiGroups: [""]
  resources:
  - nodes
  - nodes/proxy
  - services
  - endpoints
  - pods
  verbs: ["get", "list", "watch"]
- apiGroups:
  - extensions
  resources:
  - ingresses
  verbs: ["get", "list", "watch"]
- nonResourceURLs: ["/metrics"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: prometheus
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: prometheus
subjects:
- kind: ServiceAccount
  name: prometheus
  namespace: monitoring



为prometheus创建专用的kubelet访问token:
# prometheus-kubelet-token.yaml
apiVersion: v1
kind: Secret
metadata:
  name: prometheus-kubelet-token
  namespace: monitoring
  annotations:
    kubernetes.io/service-account.name: prometheus
type: kubernetes.io/service-account-token
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: prometheus-kubelet-access
rules:
- apiGroups: [""]
  resources: ["nodes", "nodes/proxy", "nodes/metrics"]
  verbs: ["get", "list", "watch"]
- nonResourceURLs: ["/metrics", "/metrics/cadvisor", "/metrics/probes"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: prometheus-kubelet-access
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: prometheus-kubelet-access
subjects:
- kind: ServiceAccount
  name: prometheus
  namespace: monitoring


检查kuelet服务状态;
# systemctl status kubelet

检查防火墙规则:
# iptables -L |grep 10250    #iptables关闭则忽略

验证:
#  kubectl describe secrets -n monitoring prometheus-kubelet-token


检查RABC权限;
# kubectl auth can-i get nodes --as=system:serviceaccount:monitoring:prometheus

查看证书有效期:
openssl x509 -in /etc/kubernetes/pki/ca.crt -noout -dates


token转base64:
# kubectl get secret -n monitoring prometheus-kubelet-token -o jsonpath='{.data.token}' | base64 --decode
相关推荐
Xの哲學17 小时前
深入剖析Linux文件系统数据结构实现机制
linux·运维·网络·数据结构·算法
深圳市恒讯科技17 小时前
Linux 文件权限指南:chmod 755、644、drwxr-xr-x 解析
linux·服务器·xr
朝阳58117 小时前
Ubuntu 22.04 安装 Fcitx5 中文输入法完整指南
linux·运维·ubuntu
xingzhemengyou117 小时前
Linux taskset指令设置或查看进程的 CPU 亲和性
linux·服务器
开开心心就好17 小时前
图片格式转换工具,右键菜单一键转换简化
linux·运维·服务器·python·django·pdf·1024程序员节
永远在Debug的小殿下17 小时前
wsl安装Ubuntu and ROS2
linux·运维·ubuntu
DO_Community17 小时前
DigitalOcean容器注册表推出多注册表支持功能
服务器·数据库·docker·kubernetes
chenmingfa11018 小时前
yum安装软件报错:Could not retrieve mirrorlist http://mirrorlist.centos.org/?relea
linux·centos
dnpao18 小时前
linux onlyoffice服务向docker容器中添加中文字体
linux·运维·docker
Linux技术芯18 小时前
浅谈nvme驱动中的nvme_alloc_ns函数的实现原理和底层逻辑
linux