zoukankan      html  css  js  c++  java
  • kubernetes operator influxdb-operator 实践

    1.代码,镜像, 二进制文件

      https://github.com/xishengcai/influxdata-operator.git   fork 之官方

    2. build 包中已经编译好二进制文件

      cd influxdata-operator
      docker build ./build
      docker images
      docker tag {image_id} influxdb-operator:v1.0

      

    3. 创建存储

      创建 pv,pvc, storageclass

    kuectl create -f deploy/storage.yaml
    

      修改pv  nodeAffinity

      nodeAffinity:
        required:
          nodeSelectorTerms:
          - matchExpressions:
            - key: beta.kubernetes.io/arch
              operator: In
              values:
              - amd64 

      pvc 中声明storageclass 

      pv 中也声明storageclass

      pvc 最终绑定到符合storageclass条件的pv, 如果没有符合条件的pv则会pending

      storageclass 动态绑定,将pv归类,pvc 绑定符合声明的那一类pv

    4. 创建目录

    mkdir /var/lib/influxdb
    

      

    5. 创建influxdb-operator

    kubectl create -f bundle.yaml
    

      crd:Influxd

        规定了 镜像,副本数目

    apiVersion: influxdata.com/v1alpha1
    kind: Influxdb
    metadata:
      name: influxdb
    spec:
      # Add fields here
      size: 1
      baseImage: influxdb:1.6.3-alpine
      imagePullPolicy: IfNotPresent
      pod:
        resources:
          limits:
            cpu: 8
            memory: 16Gi
          requests:
            cpu: 0.1
            memory: 256Mi
        persistentVolumeClaim:
          metadata:
            name: "influxdb-data-pvc"
          spec:
            accessModes: [ "ReadWriteOnce" ]
            storageClassName: standard-resize
            resources:
              requests:
                storage: 8Gi
    

      operator: influxdata-operator

        启动operator deployment, 根据crd中的信息控制influxdb statefulset 副本状态

        operator源码中的controller-manager 监听 influxdb  statefulset 的状态,而 crd中存的就是期望的目标状态,如果不一致则进行update。

        listwatch下有add, delete, update,主要靠这三个方法实现期望状态。

        

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: influxdata-operator
    spec:
      replicas: 1
      selector:
        matchLabels:
          name: influxdata-operator
      template:
        metadata:
          labels:
            name: influxdata-operator
        spec:
          serviceAccountName: influxdata-operator
          containers:
            - name: influxdata-operator
              # Replace this with the built image name
              image: influxdb-operator:v1.0
              ports:
              - containerPort: 60000
                name: metrics
              command:
              - influxdata-operator
              imagePullPolicy: IfNotPresent
              env:
                - name: WATCH_NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
                - name: OPERATOR_NAME
                  value: "influxdata-operator"
    

      

    6. 检查pod状态

    kubectl get pod
    

     

     

    7. 获取service ip

    kubectl get svc
    

      通过kubectl get all 可以看到default namespace创建的所有的资源对象

    8.golang 代码测试

     代码地址:https://github.com/xishengcai/go_learn/blob/master/client/influxdb.go

       

    9. 数据备份

      创建pv, pvc

      创建 crd: Backup

      kubectl create -f influxdata_v1alpha1_backup_cr_pv.yaml

    apiVersion: influxdata.com/v1alpha1
    kind: Backup
    metadata:
      name: influxdb-backup
    spec:
      podname: "influxdb-0"
      containername: "influxdb"
      # [ -database <db_name> ] Optional: If not specified, all databases are backed up.
      databases:
      # [ -shard <ID> ] Optional: If specified, then -retention <name> is required.
      shard:
      # [ -retention <rp_name> ] Optional: If not specified, the default is to use all retention policies. If specified, then -database is required.
      retention:
      # [ -start <timestamp> ] Optional: Not compatible with -since.
      start:
      # [ -end <timestamp> ] Optional:  Not compatible with -since. If used without -start, all data will be backed up starting from 1970-01-01.
      end:
      # [ -since <timestamp> ] Optional: Use -start instead, unless needed for legacy backup support.
      since:
      storage:
        provider: in2
    

       

      log:kubectl logs -f influxdata-operator-b5c7cdfdf-7sr85

        

        

    10. 问题

      1.不同pod的pv没有实现数据同步

      2.没有读写分离

    没有什么是写一万遍还不会的,如果有那就再写一万遍。
  • 相关阅读:
    python 列表与字符串互相转化
    python爬虫——BeautifulSoup详解(附加css选择器)
    python——requests库
    用代理池 + redis 刷博客浏览量(2)
    scrapy爬取知乎用户信息并存入mongodb
    python 爬虫 计算博客园浏览量,刷浏览量(1)
    python SocketServer模块创建TCP服务器·
    【XSY1986】【BZOJ1455】罗马游戏
    【模板】左偏树
    CF464D World of Darkraft
  • 原文地址:https://www.cnblogs.com/waken-captain/p/10563690.html
Copyright © 2011-2022 走看看