天天看點

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

我們知道,Cluster 是 Google Kubernetes Engine (簡稱GKE)的基礎,代表容器化應用程式的 Kubernetes 對象都在叢集之上運作。

Google Kubernetes Engine (GKE) 提供了一個托管環境,開發人員可以使用 Google 基礎架構在 GKE 中部署、管理和擴縮容器化應用。GKE 環境包括多個 Compute Engine 執行個體,這些執行個體組合在一起就形成了 Google Kubernetes Cluster.

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

SAP HANA Expression 是 SAP HANA 的簡化版本,旨在在筆記本電腦和其他主機(包括雲托管的虛拟機)上運作,當然也就支援在本文剛剛描述的 Google Kubernetes Cluster 上運作。這個版本除了支援 SAP HANA傳統的記憶體資料庫功能之外,還提供 bring-your-own-language 等多種技術棧,支援微服務、預測分析和機器學習算法,以及用于建構洞察驅動應用程式的地理空間處理等特性。

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

本文将詳細介紹如何在 Google Kubernetes Cluster 上部署并使用 HANA Expression Database Service.

在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體

登入 Google Cloud Platform 控制台:

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

點選控制台左上角的 Hamburger 菜單,建立一個新的 Kubernetes Cluster:

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結
#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

維護 Cluster 的名稱,選擇恰當的版本,點選 Customize 進行定制化:

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

為 Cluster 指定 CPU 和記憶體參數,標明 Ubuntu 作為作業系統。Cluster 的尺寸設定為 1.

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

Cluster 建立完并成功部署後,點選 Connect 按鈕進行連接配接。

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

連接配接成功之後,就可以使用 Cloud Shell 操作叢集了:

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

Cloud Shell 提供了指令行的方式同 Cluster 進行互動。

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

在 Google Kubernetes Cluster 上部署 HANA Expression Database Service

使用以下指令建立一個

secret

以擷取 Docker 鏡像:

kubectl create secret docker-registry docker-secret --docker-server=https://index.docker.io/v1/ --docker-username=xxx --docker-password=yyyyyy [email protected]

建立一個 yaml 格式的部署配置檔案(Deployment Configuration File), 另存成

hxe.yaml

檔案:

kind: ConfigMap
apiVersion: v1
metadata:
  creationTimestamp: 2022-06-25T19:14:38Z
  name: hxe-pass
data:
  password.json: |+
    {"master_password" : "JERRYHana1"}
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: persistent-vol-hxe
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 150Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/hxe_pv"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: hxe-pvc
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hxe
  labels:
    name: hxe
spec:
  selector:
    matchLabels:
      run: hxe
      app: hxe
      role: master
      tier: backend
  replicas: 1
  template:
    metadata:
      labels:
        run: hxe
        app: hxe
        role: master
        tier: backend
    spec:
      initContainers:
        - name: install
          image: busybox
          command: [ 'sh', '-c', 'chown 12000:79 /hana/mounts' ]
          volumeMounts:
            - name: hxe-data
              mountPath: /hana/mounts
      volumes:
        - name: hxe-data
          persistentVolumeClaim:
             claimName: hxe-pvc
        - name: hxe-config
          configMap:
             name: hxe-pass
      imagePullSecrets:
      - name: docker-secret
      containers:
      - name: hxe-container
        image: "store/saplabs/hanaexpress:2.00.030.00.20180403.2"
        ports:
          - containerPort: 39013
            name: port1
          - containerPort: 39015
            name: port2
          - containerPort: 39017
            name: port3
          - containerPort: 8090
            name: port4
          - containerPort: 39041
            name: port5
          - containerPort: 59013
            name: port6
        args: [ "--agree-to-sap-license", "--dont-check-system", "--passwords-url", "file:///hana/hxeconfig/password.json" ]
        volumeMounts:
          - name: hxe-data
            mountPath: /hana/mounts
          - name: hxe-config
            mountPath: /hana/hxeconfig
      - name: sqlpad-container
        image: "sqlpad/sqlpad"
        ports:
        - containerPort: 3000

---
apiVersion: v1
kind: Service
metadata:
  name: hxe-connect
  labels:
    app: hxe
spec:
  type: LoadBalancer
  ports:
  - port: 39013
    targetPort: 39013
    name: port1
  - port: 39015
    targetPort: 39015
    name: port2
  - port: 39017
    targetPort: 39017
    name: port3
  - port: 39041
    targetPort: 39041
    name: port5
  selector:
    app: hxe
---
apiVersion: v1
kind: Service
metadata:
  name: sqlpad
  labels:
    app: hxe
spec:
  type: LoadBalancer
  ports:
  - port: 3000
    targetPort: 3000
    protocol: TCP
    name: sqlpad
  selector:
    app: hxe
           

這個 yaml 檔案裡定義了一個 HANA Expression 的 Docker 鏡像:

store/saplabs/hanaexpress:2.00.030.00.20180403.2

使用如下指令行将這個 Docker 鏡像部署到 Kubernetes Cluster 上:

  • kubectl create -f hxe.yaml
  • kubectl describe pods

等待部署成功結束:

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

執行指令行

kubectl get pods

,確定 pod 狀态為

Running

,然後進入 Pod 容器内部:

kubectl exec -it <<pod-name>> bash

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

此時就可以使用 SQL 指令行,連接配接運作在 Pod 裡的 HANA Expression 執行個體了:

hdbsql -i 90 -d systemdb -u SYSTEM -p HXEHana1

給資料庫添加

document store

的支援:

alter database HXE add 'docstore';

從 SQLPAD service 獲得 external IP 位址:

kubectl get services

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

有了這個外部可以通路的 IP 位址之後,通路其 3000 端口,就可以在浏覽器裡登入 SQLPAD 了:

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

點選 Sign In,建立一個 Administration account.

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

使用 Connections 菜單,連接配接 HANA Expression 執行個體裡的資料庫表:

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

kubectl get services

指令行結果清單裡找到

hxe-connect

,抄下其 External IP 位址:

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

建立一個資料庫連接配接,維護剛剛抄下來的 External IP 位址,資料庫使用者名和密碼,Tenant 等登入資訊:

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

資料庫連接配接建立連接配接之後,就可以建立一個 Query,對其進行讀寫操作。

#雲原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service在 Google Cloud Platform 上建立 Google Kubernetes Cluster 執行個體在 Google Kubernetes Cluster 上部署 HANA Expression Database Service總結

建立一個名叫 quotes 的 document store, 并插入一些測試資料:

create collection quotes;
--Create a collection for document store and insert JSON values
insert into quotes values ( { "FROM" : 'HOMER',   "QUOTE" :  'I want to share something with you: The three little sentences that will get you through life. Number 1: Cover for me. Number 2: Oh, good idea, Boss! Number 3: It wai like that when I got here.', "MOES_BAR" : 'Point(  -86.880306 36.508361 )', "QUOTE_ID" : 1  });
insert into quotes values ( { "FROM" : 'HOMER',   "QUOTE" :  'Wait a minute. Bart''s teacher is named Krabappel? Oh, I''ve been calling her Crandall. Why did not anyone tell me? Ohhh, I have been making an idiot out of myself!', "QUOTE_ID" : 2, "MOES_BAR" : 'Point( -87.182708 37.213414 )' });
insert into quotes values ( { "FROM" : 'HOMER',   "QUOTE" :  'Oh no! What have I done? I smashed open my little boy''s piggy bank, and for what? A few measly cents, not even enough to buy one beer. Weit a minute, lemme count and make sure…not even close.', "MOES_BAR" : 'Point( -122.400690 37.784366 )', "QUOTE_ID" : 3 });
           

建立一個 Column 表,開啟 Fuzzy Search 的支援:

create column table quote_analysis
(
	id integer,
	homer_quote text FAST PREPROCESS ON FUZZY SEARCH INDEX ON,
	lon_lat nvarchar(200)

);
           

将插入到 document store collection 的資料拷貝到上面的 Column 表裡:

insert into quote_analysis
with doc_store as (select quote_id, quote from quotes)
select doc_store.quote_id as id, doc_store.quote as homer_quote, 'Point( -122.676366 45.535889 )'
from doc_store;
           
select  id, score() as similarity , lon_lat, TO_VARCHAR(HOMER_QUOTE)
from quote_analysis
where contains(HOMER_QUOTE, 'wait', fuzzy(0.5,'textsearch=compare'))
order by similarity asc
           

總結