kubernetes Grafana Loki cant查询pod日志

c86crjj0  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(1)|浏览(118)

我想做一个简单的POC,看看Grafana/Loki是如何工作的,以及我如何使用它来查询我的pod日志。
我有以下设置:我使用以下配置创建了一个本地kind集群(k8s版本v1.27.1):

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker

字符串
然后我使用以下命令安装了grafana(通过prometheus helm)和loki:

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add stable https://charts.helm.sh/stable
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack
# get the UI admin password
k get secret prometheus-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

#install loki
helm repo add grafana https://grafana.github.io/helm-chartshelm repo update
helm repo update
helm install --values values.yaml loki grafana/loki --set loki.auth_enabled=false

# values.yaml content
# minio:
#   enabled: true

# port forward to access the UI
kubectl port-forward deployment/prometheus-grafana 3000


之后,我添加了来自Grafana UI Grafana UI add Loki的loki url http://loki-gateway
然后,我创建了一个简单的应用程序来验证我是否可以查询它的日志,使用以下配置:

kind: Pod
apiVersion: v1
metadata:
  name: foo-app
  labels:
    app: app1
    component: foo1
spec:
  containers:
  - name: foo-app
    image: hashicorp/http-echo:0.2.3
    args:
    - "-text=hello from namespace default"
---
kind: Service
apiVersion: v1
metadata:
  name: foo1
spec:
  type: LoadBalancer
  selector:
    component: foo1
  ports:
  # Default port used by the image
  - port: 5678


当我访问应用程序时,我可以看到来自kubectl logs foo-app的日志:

2023/06/13 14:30:27 Server is listening on :5678
2023/06/13 14:30:43 localhost:3001 127.0.0.1:60142 "GET / HTTP/1.1" 200 29 "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0" 65.864µs
2023/06/13 14:30:45 localhost:3001 127.0.0.1:60142 "GET / HTTP/1.1" 200 29 "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0" 56.885µs
2023/06/13 14:30:46 localhost:3001 127.0.0.1:60142 "GET / HTTP/1.1" 200 29 "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0" 9.868µs


我在洛基看不到它的日志。在我看来,洛基看不到这个豆荚的存在。Grafana Loki UI
我认为这可能与Loki权限有关,但查看群集角色,权限似乎就在那里。我还错过了什么
我试图重新创建自定义应用程序没有任何成功。我还尝试再次向LokiClusterRole添加更多权限,但没有成功

3htmauhk

3htmauhk1#

最后,我用promtail helm chart将日志发送给loki,使用以下配置:

config:
  clients:
    - url: http://loki-gateway/loki/api/v1/push
      tenant_id: 1
  snippets:
    pipelineStages:
      - docker: {}

字符串

相关问题