1.代碼,鏡像, 二進制文件node
https://github.com/xishengcai/influxdata-operator.git fork 之官方git
2. build 包中已經編譯好二進制文件github
cd influxdata-operator docker build ./build
docker images
docker tag {image_id} influxdb-operator:v1.0
3. 建立存儲golang
建立 pv,pvc, storageclassdocker
kuectl create -f deploy/storage.yaml
修改pv nodeAffinityapi
nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: beta.kubernetes.io/arch operator: In values: - amd64
pvc 中聲明storageclass app
pv 中也聲明storageclassless
pvc 最終綁定到符合storageclass條件的pv, 若是沒有符合條件的pv則會pendingide
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.沒有讀寫分離