k8s中部署grafna

storageClass配置参考:http://www.duozhi.online/2023/10/20/nfs-server%e5%ae%89%e8%a3%85k8s%e4%b8%ad%e9%83%a8%e7%bd%b2nfs-provisionernfs-server%e5%ae%89%e8%a3%85/

storageClassName: managed-nfs-storage设置为我们上面搭建的名字,其他根据需要修改即可

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana-pvc
  namespace: middleware
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: managed-nfs-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: middleware
spec:
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      securityContext:
        fsGroup: 472
        supplementalGroups:
          - 0
      containers:
        - name: grafana
          image: grafana/grafana:8.5.5
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000
              name: http-grafana
              protocol: TCP
          resources:
            requests:
              cpu: 500m
              memory: 1Gi
            limits:
              cpu: 500m
              memory: 1Gi
          volumeMounts:
            - mountPath: /var/lib/grafana
              name: grafana-pv
      volumes:
        - name: grafana-pv
          persistentVolumeClaim:
            claimName: grafana-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: middleware
spec:
  ports:
    - port: 3000
      protocol: TCP
      targetPort: http-grafana
      nodePort: 30081
  selector:
    app: grafana
  type: NodePort

数据存储在pvc中

对应在nfs服务端地址为

参考文献

https://grafana.com/docs/grafana/v9.0/setup-grafana/installation/kubernetes/
https://blog.csdn.net/lovely_nn/article/details/124385380
Pvc pending报错,参考了如下
https://blog.csdn.net/m0_46090675/article/details/122286289
后来我又kubectl delete -f api-server.yaml也不报错了,不能有两个api-server
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
KubernetesK8s部署Prometheus可以通过以下步骤完成: 1. 创建命名空间(可选):可以选择在K8s创建一个专门用于Prometheus的命名空间,以便更好地组织和管理资源。可以使用以下命令创建一个命名空间: ``` kubectl create namespace prometheus ``` 2. 创建配置文件:创建一个Prometheus的配置文件(例如prometheus.yaml),用于定义监控目标和规则。可以参考Prometheus的官方文档(https://prometheus.io/docs/prometheus/latest/configuration/configuration/)了解更多配置选项。 3. 创建ConfigMap:将配置文件作为ConfigMap对象添加到K8s集群,以便在部署使用。可以使用以下命令创建ConfigMap: ``` kubectl create configmap prometheus-config --namespace=prometheus --from-file=prometheus.yaml ``` 4. 创建服务和部署:创建一个Service和Deployment对象来部署Prometheus。Service用于将Prometheus暴露给其他服务,Deployment用于定义Pod的副本数量和其他设置。可以使用以下示例yaml文件创建Service和Deployment: ``` apiVersion: v1 kind: Service metadata: name: prometheus namespace: prometheus spec: ports: - name: http port: 9090 targetPort: 9090 selector: app: prometheus --- apiVersion: apps/v1 kind: Deployment metadata: name: prometheus namespace: prometheus spec: replicas: 1 selector: matchLabels: app: prometheus template: metadata: labels: app: prometheus spec: containers: - name: prometheus image: prom/prometheus ports: - containerPort: 9090 volumeMounts: - name: config-volume mountPath: /etc/prometheus/prometheus.yaml subPath: prometheus.yaml volumes: - name: config-volume configMap: name: prometheus-config ``` 可以将上述内容保存为prometheus.yaml文件,并使用以下命令进行部署: ``` kubectl apply -f prometheus.yaml ``` 5. 访问Prometheus:完成部署后,可以通过Service的Cluster IP和端口(默认为9090)来访问Prometheus的Web界面。可以使用以下命令获取Service的IP地址和端口: ``` kubectl get svc prometheus -n prometheus ``` 在浏览器访问`http://<cluster_ip>:<port>`即可进入Prometheus的Web界面。 这些是在Kubernetes部署Prometheus的基本步骤。你可以根据需要进行进一步的配置和定制化,例如添加监控目标、定义告警规则
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值