常见问题
查看Collector日志
进入容器
kubectl exec -it tingyun-collector-0 -n tingyun -- bash
在容器内部执行
# APM Collector日志
cd /opt/tingyun-collector/logs/apm
# Infra Collector日志
cd /opt/tingyun-collector/logs/infra
# Guanyun Collector日志
cd /opt/tingyun-collector/logs/guanyun
安装探针都需要什么权限?
安装探针需要 MutatingWebhookConfiguration、ClusterRoleBinding 和 ClusterRole 权限。
-
嵌入APM探针的原理是通过在集群内安装一个Webhook服务,此Webhook服务拦截Pod启动命令并对指定Pod追加initContainer来嵌入APM探针,安装Webhook服务需要MutatingWebhookConfiguration的权限。
为了实现限制同一Deployment内Pod嵌码的数量的功能,Webhook服务启动时需要通过Kubernetes API获取集群内已嵌码的Pod信息,获取Pod资源的只读权限,并对探针所属的账号赋权。
定义资源的读取权限需要ClusterRole的权限,对探针所属的账号赋权需要ClusterRoleBinding的权限。
-
Infra探针集成了监控Kubernetes集群信息的组件,原理是通过Kubernetes API获取集群内的相关信息,而调用Kubernetes API需要特定资源的 读取权限,并对探针所属的账号赋权。
定义资源的读取权限需要ClusterRole的权限,对探针所属的账号赋权需要ClusterRoleBinding的权限。
为了最小化探针的权限,Infra探针使用ClusterRole权限时仅申请了Pod、Namespace 等实体资源的list watch get只读操作的权限,为了保证可以从探针所在的Pod内部访问kubernetes API server,需要申请tokenreviews和subjectaccessreviews资源的create权限。
缺少相应权限时,会报以下错误:
Error from server (Forbidden): error when retrieving current configuration of:
Resource: "admissionregistration.k8s.io/v1beta1, Resource=mutatingwebhookconfigurations", GroupVersionKind: "admissionregistration.k8s.io/v1beta1, Kind=MutatingWebhookConfiguration"
Name: "tingyun-agent-webhook", Namespace: ""
from server for: "./agent.yaml": mutatingwebhookconfigurations.admissionregistration.k8s.io "tingyun-agent-webhook" is forbidden:
User "limited" cannot get resource "mutatingwebhookconfigurations" in API group "admissionregistration.k8s.io" at the cluster scope
Error from server (Forbidden): error when retrieving current configuration of:
Resource: "rbac.authorization.k8s.io/v1, Resource=clusterroles", GroupVersionKind: "rbac.authorization.k8s.io/v1, Kind=ClusterRole"
Name: "tingyun-k8s-monitor", Namespace: ""
from server for: "./agent.yaml": clusterroles.rbac.authorization.k8s.io "tingyun-k8s-monitor" is forbidden:
User "limited" cannot get resource "clusterroles" in API group "rbac.authorization.k8s.io" at the cluster scope
Error from server (Forbidden): error when retrieving current configuration of:
Resource: "rbac.authorization.k8s.io/v1, Resource=clusterrolebindings", GroupVersionKind: "rbac.authorization.k8s.io/v1, Kind=ClusterRoleBinding"
Name: "tingyun-k8s-monitor", Namespace: ""
from server for: "./agent.yaml": clusterrolebindings.rbac.authorization.k8s.io "tingyun-k8s-monitor" is forbidden:
User "limited" cannot get resource "clusterrolebindings" in API group "rbac.authorization.k8s.io" at the cluster scope
当出现以上错误时,请搜索安装的yaml文件内的管理员权限关键字,并将相关yaml内容交给集群管理员审核执行。
排查APM探针嵌码故障
业务Pod启动失败
查看Pod描述信息是否异常
kubectl describe pod [应用pod名] -n [应用所在的namespace]
查看事件信息是否异常
kubectl get event -n [应用所在的namespace]
查看Pod InitContainer日志
kubectl logs [应用pod名] -c tingyun-oneagent -n [应用所在的namespace]
常见原因:
-
InitContainer报错
exec /bin/sh exec format error,说明镜像和当前Node CPU架构不一致,请检查镜像的CPU架构,如果集群内既有ARM64又有AMD64的Node节点,请开启镜像manifest功能,并上传自适应架构的镜像。
-
Node节点的CPU或内存不足导致启动失败,使用命令
kubectl top node查看Node资源情况。 -
加上探针后,进程CPU内存占用会比原来略有增高,可能导致超过yaml描述文件内CPU和内存的limit限制,查看yaml内limit值。
-
加上探针后,启动时间会变长,可能触发Pod健康检查失败,查看健康检查策略。
业务Pod启动成功,嵌码成功,但业务应用访问故障
常见原因:
-
探针启动慢,查看业务应用日志和探针日志。
-
探针兼容性有问题,查看业务应用日志和探针日志。
业务Pod启动成功,嵌码失败
APM 探针嵌码分为2个大的阶段:
-
将探针镜像文件挂载到应用Pod文件系统。
-
应用Pod启动后,应用进程根据语言类型加载探针。
使用以下命令检查应用Pod是否挂载探针镜像文件:
kubectl describe pod [应用pod名] -n [应用所在的namespace] | grep tingyun-oneagent
例如:以下输出为已挂载状态
LD_PRELOAD: /opt/tingyun-oneagent/lib/libinterceptor.so
/opt/tingyun-oneagent from oneagent-volume (rw)
如果未挂载探针镜像文件,请按照步骤1-6排查, 如果已挂载探针镜像文件,请按照步骤7-12排查。
步骤1. 检查基调听云的Pod运行状态。
查看探针Pod状态:
kubectl get pod -n tingyun
输出内容应该类似如下:
NAME READY STATUS RESTARTS AGE
cluster-metrics-76db8d69fd-pnv86 1/1 Running 0 23h
kubelet-metrics-ls847 1/1 Running 0 23h
tingyun-collector-0 1/1 Running 0 23h
tingyun-linux-agent-xk8pp 1/1 Running 0 22h
tingyun-webhook-6b96bc4f68-cggd6 1/1 Running 0 23h
tingyun-webhook-xxx 的状态应该为Running状态。
如果状态不等于Running,请使用 kubectl describe pod tingyun-webhook-xxx -n tingyun 查看pod的描述信息。
通常错误原因包括:镜像源网络不通、镜像CPU架构不匹配(ARM64或AMD64 )、集群内CPU或内存资源不足 等。
如果没有任何Pod信息,请使用kubectl查看deployment和replicaset的信息中是否有报错信息:
kubectl -n tingyun get all
kubectl -n tingyun describe deployment/tingyun-webhook
kubectl -n tingyun describe replicaset-controller/tingyun-webhook-xxx
例如在时速云平台,会有以下报错:
Warning FailedCreate 2m18s (x15 over 7m46s) replicaset-controller Error creating:
pods "tingyun-webhook-675f7797db-" is forbidden: PodSecurityPolicy: unable to admit pod: []
如果出现PodSecurityPolicy错误,需要修改yaml中ClusterRole部分,添加PSP策略
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: tingyun-k8s-monitor
rules:
# 如果开启了PSP使用权限,需放开下面注释, 查看已有的PSP策略: kubectl get psp
#- apiGroups:
# - policy
# resourceNames:
# - system # 绑定可用的PSP策略,如果开启Infra,需要绑定privileged权限
# resources:
# - podsecuritypolicies
# verbs:
# - use
查看探针服务状态:
kubectl get svc -n tingyun
输出内容应该类似如下:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cluster-metrics-service ClusterIP 10.98.193.238 <none> 80/TCP 23h
tingyun-collector-service ClusterIP 10.107.120.36 <none> 7665/TCP,7666/TCP 23h
tingyun-webhook-service ClusterIP 10.99.222.1 <none> 443/TCP 23h
列表内应该包含tingyun-webhook-service服务和tingyun-collector-service和cluster-metrics-service服务
步骤2. 检查需嵌码应用所在Namespace的Label。
kubectl get namespace -L tingyun-injection
输出内容应该类似如下:
NAME STATUS AGE TINGYUN-INJECTION
default Active 20d
test Active 9d enabled
tingyun Active 8d
嵌码应用所在Namespace的tingyun-injection标签应该为enabled。
步骤3. 检查需嵌码应用所在Pod的Label。
kubectl describe pod www.tomcat.com-689b69775f-s7tcl -n test
输出内容应该类似如下:
Name: www.tomcat.com-689b69775f-s7tcl
Namespace: test
Labels: tingyun-agent-injected=enabled
Annotations: tingyun-agent-id: 5022f18b-1944-11ed-b5a0-02427e459e42
嵌码应用所在Pod的tingyun-agent-injected标签应该为enabled