• Mac系统配置k8s completion命令补全


    Loki版本

    环境准备

    • helm工具安装

    • k8s环境支持,可以直接使用docker桌面工具自带的k8s工具便于进行资源分配

    安装

    • 拉取grafana:

      helm repo add grafana https://grafana.github.io/helm-charts
      
      • 1
    • 部署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
      
      • 1
    • 等待对应的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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 修改loki-grafana的网络类型
    kubectl edit svc loki-grafana
    
    将spec.type从ClusterIP改为NodePort
    :wq
    service/loki-grafana edited
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 查看k8s为loki-grafana分配的外网IP
    kubectl get svc |grep loki-grafana
    loki-grafana  NodePort    10.97.189.58     <none>   80:30580/TCP                   7m28s
    
    • 1
    • 2
    • 使用浏览器访问:localhost:30580

    • 登录grafana

      • 用户名默认为:admin

      • 密码

      kubectl get secret loki-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
      
      sQqlBCxLKpafa01cFYNrzHPpnjfY6O9rHimVhoq6
      
      • 1
      • 2
      • 3
    • 查看grafana的数据源配置
      [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ma4GNd9H-1660722951888)(image/数据源配置1.png)]
      [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CynwCllt-1660722951889)(image/数据源配置2.png)]

    服务准备

    • 编写go服务如下
    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")
    		}
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 编译生成镜像并传送到远端,
    # 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 使用k8s在本地创建服务pod
    # 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 执行查看
    # 启动
    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 在grafana查看日志
      在这里插入图片描述
      在这里插入图片描述
  • 相关阅读:
    Android车载应用开发之出识Android Automotive
    文献阅读01_基于深度学习的个性化新闻推荐方法研究_20221114
    Day12力扣打卡
    云原生之持续交付
    在 Windows 10 | Docker Desktop | Kubernetes 环境 使用 hostPath / local 为 POD 配置本机目录
    使用vscode编辑markdown文件(可粘贴截图)
    Unity 实现原神中的元素反应
    ROS系统运行yolo找不到包
    单链表OJ题(2):反转链表(三指针法)、找中间节点(快慢指针)
    没网络也能安装.Net 3.5!如何脱机安装.NET Framework 3.5
  • 原文地址:https://blog.csdn.net/double_happiness/article/details/126374753