Monday 26 March 2018

Your SAP on Azure: SAP HANA Express on Azure Kubernetes Cluster (AKS)

Using a docker image to install SAP HANA express edition can shorten the deployment time and ensure the consistency between environments. The easy way to use it is to build a Kubernetes cluster using Microsoft Azure Container Service and deploy containers in the cloud.

A docker container is a package of libraries and system settings required to run an application. It allows to save the time needed to provide a working environment and you can focus on the target database configuration. It’s great especially in environments where you need to provide separated HANA instances for many developers.

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

Azure Container Service simplifies the creation and configuration of the Kubernetes cluster and management of the entire docker environment. The nodes of the cluster are managed by Azure while your responsibility is to maintain the running application.

CREATE THE KUBERNETES CLUSTER

Creation of Kubernetes cluster in Microsoft Azure is a relatively easy task. During the initial configuration, you will be asked to provide a service principal that will be used to manage the Azure resources. Log in to the portal, go to the Azure Active Directory and create new application registration:

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

Save the settings. It is not important what you type in the Sign-on URL. Generate the key in the application settings – copy it together with the application ID – you will be asked for those details in few minutes.

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

To deploy Kubernetes cluster you need to create an Azure Cluster Service (preview). In the first step, you are asked to choose a cluster name and select a resource group in which it will be created.

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

You need to provide the basic configuration on the second screen. In the Service Principal ID and Service Principal Client Secret enter the information generated during the app registration. Choose the number of nodes and their size – I chose two DS11_V2 servers which fulfill the SAP HANA database memory and CPU requirements:

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

To connect to the cluster you require the Azure CLI. You need also to install the AKS libraries.

az aks install-cli

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

Log in to your Azure account and connect with the Kubernetes cluster

az login 
az aks get-credentials --resource-group=<resource group name> --name=<cluster name>

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

Once we have established the connection we can display the Kubernetes cluster nodes:

kubectl get nodes

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

You can validate the information in the Azure portal:

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

The nodes of the clusters are standard virtual machines in a single Availability Set:

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

DEPLOY SAP HANA

Downloading an SAP HANA database image from the Docker website requires an authentication. Provide your username and password to create a secret:

kubectl create secret docker-registry docker-secret --docker-server=https://index.docker.io/v1/ --docker-username=<username> --docker-password=<password> --docker-email=<e-mail>

Copy the deployment script and save it to your local drive:

kind: ConfigMap
apiVersion: v1
metadata:
  creationTimestamp: 2018-01-18T19:14:38Z
  name: hxe-pass
data:
  password.json: |+
    {"master_password" : "HXEHana1"}
---
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: v1
kind: Pod
metadata:
  name: hxe-pod
  labels:
    name: hxe-pod
spec:
  initContainers:
    - name: install
      image: busybox
      command: [ 'sh', '-c', 'chown 12000:79 /hana/mounts' ]
      volumeMounts:
        - name: hxe-data
          mountPath: /hana/mounts
  restartPolicy: OnFailure
  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.022.00.20171211.1"
    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

Deploy the image using the command:

kubectl create -f hana.yaml

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

The deployment takes several minutes to finish and can be monitored using the below command. If you see the message Started Container it means the process is completed.

kubectl describe pod hana-pod

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

You can now log in to the container and verify that the instance is running:

kubectl exec -it hxe-pod bash
HDB info
hdbsql -i 90 -d HXE -u SYSTEM -p <password>

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

You can see on which node the pod is running by executing:

kubectl get pods -o wide

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

NODE SELECTION: DIRECT ASSIGNMENT

You can directly assign the node to which the container should be deployed by a Node Selector segment:

  containers:
  - name: hxe-container
    image: "store/saplabs/hanaexpress:2.00.022.00.20171211.1"
    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
  nodeSelector:
    kubernetes.io/hostname: aks-agentpool-25335148-1

Deploy the cluster using the modified configuration file.

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

NODE SELECTION: MEMORY REQUIREMENTS

The other possibility to help the cluster to choose good node is to specify a minimum memory requirement. The virtual machine with SAP HANA express edition requires at least 8GB of memory, but as the docker should consume a smaller amount of RAM I have requested only 7GB.

  containers:
  - name: hxe-container
    image: "store/saplabs/hanaexpress:2.00.022.00.20171211.1"
    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
    resources:
      requests:
        memory: "7Gi"

The current hardware utilization can be displayed using:

kubectl top nodes

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

The two previously deployed containers consume more than 10 GB of memory on node 1, therefore, the cluster creates the third HANA instance on node 0.

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

SCALE-OUT THE KUBERENETES CLUSTER

Let’s try to create one more instance:

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

As there is not enough available memory on any of the node, the container was not deployed and has status pending. In that case, you can scale-out the Kubernetes cluster and add the third node:

az aks scale --name <resource name> --resource-group <resource group> --node-count <nodes>

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

When we check the pod status again, we can see that the hxe-pod4 is assigned to the newly created node 2.

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

KUBERNETES CLUSTER DASHBOARD

Instead of using the command line interface some tasks can be executed from the Kubernetes Dashboard. The bellow command creates a proxy to the Kubernetes engine in Azure and allows you to contact the webpage through a localhost:

az aks browse --resource-group <resource group> --name <cluster name>

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

Open a browser and navigate to http://127.0.0.1:8001/ to display the dashboard.

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

REMOTE DATABASE ACCESS

If you wish to access the database from the Internet you can configure the load balancer. Execution of bellow command creates a new service and assigns the Public IP.

kubectl expose pod <pod name> --name=<service name> --type=LoadBalancer
kubectl get service <service name>

SAP HANA Tutorials and Materials, SAP HANA Learning, SAP HANA Guides, SAP HANA Certifications

No comments:

Post a Comment