v2.4.x
helm工具安装
k8s环境支持,可以直接使用docker桌面工具自带的k8s工具便于进行资源分配
拉取grafana:
helm repo add grafana https://grafana.github.io/helm-charts
部署Loki Stack,一次安装 Loki、Promtail、Grafana、Prometheus工具
helm upgrade --install loki grafana/loki-stack --set grafana.enabled=true,prometheus.enabled=true,prometheus.alertmanager.persistentVolume.enabled=false,prometheus.server.persistentVolume.enabled=false
等待对应的pod都起来
kubectl get pod
NAME READY STATUS RESTARTS AGE
loki-0 0/1 Running 0 42s
loki-grafana-5d5c4c8df-mrlg9 2/2 Running 0 42s
loki-kube-state-metrics-5c6b9ddd4f-kdh56 1/1 Running 0 42s
loki-prometheus-alertmanager-7d5bdfcb7b-mzgl7 2/2 Running 0 42s
loki-prometheus-node-exporter-2f4kc 0/1 RunContainerError 2 42s
loki-prometheus-pushgateway-7cdf755958-4zj99 1/1 Running 0 42s
loki-prometheus-server-6764f67456-c7qmn 2/2 Running 0 42s
loki-promtail-n9p74 1/1 Running 0 42s
loki-grafana
的网络类型kubectl edit svc loki-grafana
将spec.type从ClusterIP改为NodePort
:wq
service/loki-grafana edited
kubectl get svc |grep loki-grafana
loki-grafana NodePort 10.97.189.58 <none> 80:30580/TCP 7m28s
使用浏览器访问:localhost:30580
登录grafana
用户名默认为:admin
密码
kubectl get secret loki-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
sQqlBCxLKpafa01cFYNrzHPpnjfY6O9rHimVhoq6
查看grafana的数据源配置
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ma4GNd9H-1660722951888)(image/数据源配置1.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CynwCllt-1660722951889)(image/数据源配置2.png)]
package main
import (
"log"
"time"
)
func main() {
t := time.NewTicker(2*time.Second)
for {
select {
case <-t.C:
log.Println("log")
log.Println("log1")
log.Println("log2")
log.Println("log3")
log.Println("log4")
log.Println("log5")
log.Println("log6")
}
}
}
# Dockerfile
FROM golang:alpine
RUN mkdir /app
COPY . /app
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
# build-docker.sh
docker login --username=zsx123456 --password=xxxxxxxx
docker build -t zsx123456/go-loki .
docker push zsx123456/go-loki
# 执行build-docker
sh build-docker.sh
# deployment.yaml
apiVersion: apps/v1 # 当前使用的 kubernetes 的API版本
kind: Deployment # 表示想要创建的对象种类
metadata: # 元数据,用于唯一表示当前的对象
name: go-loki # fdsf
spec: # pod的指定配置
replicas: 2 #ReplicaSet部分的定义
selector:
matchLabels:
app: go-app
template: # Pod 模板的定义
metadata:
labels:
app: go-app
spec: # pod中容器相关的定义
containers:
- name: go-app-container
image: zsx123456/go-loki
ports:
- containerPort: 3000
# 启动
kubectl create -f deployment.yaml
deployment.apps/go-loki created
# 查看pod
kubectl get pods |grep go-loki
go-loki-54f6d7f4c9-sbq64 1/1 Running 0 42s