在k8s上部署Loki日志查询工具
来源:原创
时间:2020-07-07
作者:脚本小站
分类:云原生
通过heml去部署Loki,要先安装heml:
wget https://get.helm.sh/helm-v2.16.9-linux-amd64.tar.gz tar -xf helm-v2.16.9-linux-amd64.tar.gz -C /usr/local/ mv linux-amd64/ helm cat > /etc/profile.d/helm.sh <<EOF export PATH=$PATH:/usr/local/helm EOF source /etc/profile.d/helm.sh
为tiller赋予权限:这是helm2,helm3不用安装tiller。
cat > helm-rbac.yaml <<EOF apiVersion: v1 kind: ServiceAccount metadata: name: tiller namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: tiller roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: tiller namespace: kube-system EOF kubectl apply -f helm-rbac.yaml
初始化tiller:
helm init --service-account tiller
查看版本:
$ helm version Client: &version.Version{SemVer:"v2.16.9", GitCommit:"8ad7037828e5a0fca1009dabe290130da6368e39", GitTreeState:"clean"} Server: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
安装Loki:
先测试heml源:
helm search
添加Loki源:
helm repo add loki https://grafana.github.io/loki/charts
查找Loki:
$ helm search repo loki NAME CHART VERSION APP VERSION DESCRIPTION loki/loki 0.30.1 v1.5.0 Loki: like Prometheus, but for logs. loki/loki-stack 0.38.1 v1.5.0 Loki: like Prometheus, but for logs. loki/fluent-bit 0.1.4 v1.5.0 Uses fluent-bit Loki go plugin for gathering logs and sen... loki/promtail 0.23.2 v1.5.0 Responsible for gathering logs and sending them to Loki
安装:选择 loki/loki-stack 这个包,安装了就全都有了包括Loki和promtail
helm upgrade --install loki loki/loki-stack -n monitoring
在grafana中添加数据源:
Configuration->Data Source:选择Loki后在URL中填写k8s的dns解析地址或NodePort方式都可以。
http://loki:3100
在左侧栏Explore中可查询日志等操作。
卸载命令:
helm uninstall loki loki/loki-stack -n loki