Saturday 10 March 2018

Deploy drill-sqlline docker image in a Kubernetes cluster


Aim:

Deploy the drill-sqlline image build using Build drill-sqlline Docker image in a Kubernetes cluster.

Steps:

[1] Create a namespace for DRILL. (Optional, but this is useful if you want to implement RBAC.)
a. Create a file 'drillsqlline-namespace.yaml' with following contents:
apiVersion: v1
kind: Namespace
metadata:
  name: drill-system
  labels:
    name: drill-system

It specifies to create a NameSpace called 'drill-system'.

b. Execute the following command to create the namespace.
kubectl create -f drillsqlline-namespace.yaml

[2] Create pod drill-sqlline.
For this, we will use the docker image we created as per - Build drill-sqlline Docker image
a. Create a file 'drillsqlline-pod.yaml' with following contents:
apiVersion: v1
kind: Pod
metadata:
      name: drill-sqlline-pod
      namespace: drill-system
spec:
    containers:
    - name: base
      imagePullPolicy: Always
      image: jamealwi/drill-sqlline:latest
      resources:
        requests:
          memory: "1Gi"
          cpu: "500m"
      command:
      - /bin/bash
      - -c
      - exec /sbin/init

It specifies to create a pod inside 'drill-system' namespace by pulling image 'jamealwi/drill-sqlline:latest'.

b. Execute the following command to create the pod inside 'drill-system' namespace.
kubectl create -f drillsqlline-pod.yaml -n drill-system

At this point, your pod should be up and running.

You can verify it by running the following command:
kubectl get pods -n drill-system

[root@vmdocc7176 mapr]# kubectl get pods -n drill-system
NAME                                        READY     STATUS    RESTARTS   AGE
drill-sqlline-pod                           1/1       Running   0          1m
[root@vmdocc7176 mapr]#

Now you can log in to your pod and then log in to sqlline as given below:
kubectl exec -it drill-sqlline-pod  -n drill-system -- bash

[root@vmdocc7176 mapr]# kubectl exec -it drill-sqlline-pod  -n drill-system -- bash
[root@drill-sqlline-pod /]# ./sqlline
apache drill
"just drill it"
1: jdbc:drill:zk=10.10.XX.YYY:5181> !connect jdbc:drill:drillbit=10.10.XX.YYY:31010
Enter username for jdbc:drill:drillbit=10.10.XX.YYY:31010: username
Enter password for jdbc:drill:drillbit=10.10.XX.YYY:31010: password
2: jdbc:drill:drillbit=10.10.XX.YYY:31010>

[3] Creating a deployment
However, in a PROD setup, you will work mostly with 'Deployments' which will internally create the specified number of pods and maintain them.
Follow below steps to create 'Deployment' for drill-sqlline.

a. Create a file 'drillsqlline-deployment.yaml' with the following contents: 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: drill-sqlline-deployment
  labels:
    app: drill-sqlline
spec:
  replicas: 2
  selector:
    matchLabels:
      app: drill-sqlline
  template:
    metadata:
      labels:
        app: drill-sqlline
    spec:
      containers:
      - name: drill-sqlline
        image: jamealwi/drill-sqlline:latest
        resources:
          requests:
            memory: "1Gi"
            cpu: "500m"
        command:
        - /bin/bash
        - -c
        - exec /sbin/init

It specifies to create 2 pods 'drill=sqlline' with docker image 'jamealwi/drill-sqlline:latest'.

b. Execute the following command to create the deployment inside 'drill-system' namespace.
kubectl create -f drillsqlline-pod.yaml -n drill-system

Verify the deployment is successful using below command:

[root@vmdocc7176 mapr]# kubectl get deployments -n drill-system
NAME                       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
drill-sqlline-deployment   2         2         2            2           55m
[root@vmdocc7176 mapr]# kubectl get pods -n drill-system
NAME                                        READY     STATUS    RESTARTS   AGE
drill-sqlline-deployment-6748b795f7-7xdvv   1/1       Running   0          55m
drill-sqlline-deployment-6748b795f7-jczrk   1/1       Running   0          55m


No comments:

Post a Comment