<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Raju Pavuluri on Medium]]></title>
        <description><![CDATA[Stories by Raju Pavuluri on Medium]]></description>
        <link>https://medium.com/@rajupavuluri?source=rss-ddf26189cbf8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wNGbiwhaBsyHc_8M.jpg</url>
            <title>Stories by Raju Pavuluri on Medium</title>
            <link>https://medium.com/@rajupavuluri?source=rss-ddf26189cbf8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 09:15:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajupavuluri/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[GPU load based autoscaling on Kubernetes clusters]]></title>
            <link>https://medium.com/@rajupavuluri/how-to-autoscale-your-ray-programs-based-on-gpu-load-on-kubernetes-clusters-9ba75d46b71b?source=rss-ddf26189cbf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ba75d46b71b</guid>
            <dc:creator><![CDATA[Raju Pavuluri]]></dc:creator>
            <pubDate>Fri, 30 Jul 2021 14:59:47 GMT</pubDate>
            <atom:updated>2021-08-10T13:54:02.534Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iAFG6tDpyyDqHXr85p9NBg.jpeg" /></figure><p>So we have a Kubernetes cluster. It can recognize GPUs on your nodes and use them. Even the GPU metrics are exposed through dcgm-exporter and prometheus stack. What next? We know we could autoscale our programs on Kubernetes cluster with Horizontal Pod Autoscaler based on CPU and memory usage. Can we do the same with GPU metrics — the answer is yes, Prometheus Adapter comes to the rescue.</p><p>This article assumes you have a Kubernetes cluster enabled to work with GPUs, and you are using dcgm and prometheus stack for GPU metrics. If not, you can follow my previous articles on how to get there. My Kubernetes version is 1.20.2, and I have Tesla V100 GPUs . These instructions have been tried on rhel/centos7 .</p><p>We have Prometheus acting as a metrics provider — we configured it to provide us GPU metrics earlier. Prometheus Adapter provides us Custom Metrics API, pulling metrics served by external metrics provider, in this case Prometheus. These custom metrics can then be used by Horizontal Pod Autoscalers to scale workloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*uYrv0GVACd2jQ-ExQOmP3w.png" /></figure><p>Before we install Prometheus Adapter, let’s check the url to connect to prometheus. It will come in handy later when configuring our adapter.</p><pre># kubectl get svc -n prometheus<br>NAME                                                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE<br>alertmanager-operated                                       ClusterIP   None             &lt;none&gt;        9093/TCP,9094/TCP,9094/UDP   1d<br>kube-prometheus-stack-1614-alertmanager                     ClusterIP   10.97.150.200    &lt;none&gt;        9093/TCP                     1d<br>kube-prometheus-stack-1614-operator                         ClusterIP   10.107.120.24    &lt;none&gt;        443/TCP                      1d<br>kube-prometheus-stack-1614-prometheus                       NodePort    10.106.243.247   &lt;none&gt;        9090:30090/TCP               1d<br>kube-prometheus-stack-1614100923-grafana                    NodePort    10.100.30.205    &lt;none&gt;        80:32197/TCP                 1d<br>kube-prometheus-stack-1614100923-kube-state-metrics         ClusterIP   10.111.133.205   &lt;none&gt;        8080/TCP                     1d<br>kube-prometheus-stack-1614100923-prometheus-node-exporter   ClusterIP   10.110.160.60    &lt;none&gt;        9100/TCP                     1d<br>prometheus-operated                                         ClusterIP   None             &lt;none&gt;        9090/TCP                     1d</pre><p>Note that our service is prometheus-operated running in prometheus name space available at port 9090. So our prometheus url to be used by the adapter would be <a href="http://prometheus-operated.prometheus.svc/">http://prometheus-operated.prometheus.svc</a> with 9090 as port.</p><h4>Install Prometheus Adapter</h4><p>Installation of Prometheus Adapter is super easy with helm, but there is some configuration involved to setup Prometheus metrics and Kubernetes resources discovery and presentation of those metrics through custom metrics API. Technically, this can also be done vial helm install command as documented at <a href="https://github.com/kubernetes-sigs/prometheus-adapter">https://github.com/kubernetes-sigs/prometheus-adapter</a>. However, that did not work for me. I ended up pulling the helm chart, modified it the values with custom configuration, then installed. Here are the steps.</p><p>Pull the helm chart into a temporary folder.</p><pre>helm pull prometheus-community/prometheus-adapter</pre><p>This will give you the latest version of adapter helm charts in a zip file — prometheus-adapter-2.15.2.tgz . Unzip this file and go to prometheus-adapter folder.</p><pre>tar -xvzf ../prometheus-adapter-2.15.2.tgz</pre><pre>cd prometheus-adapter/</pre><p>Edit values.yaml file in your favorite editor. Find the url for prometheus and change it from the default to what we have. It should look like this.</p><pre># Url to access prometheus<br>prometheus:<br>  # Value is templated<br>  url: <a href="http://prometheus-operated.prometheus.svc/">http://prometheus-operated.prometheus.svc</a><br>  port: 9090<br>  path: &quot;&quot;</pre><p>Now find the section for rules and copy the following configuration. For a deeper understanding of these rules, you can have a look at <a href="https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/docs/config-walkthrough.md">https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/docs/config-walkthrough.md</a>.</p><p>Here we are using DCGM exported GPU metrics (refer to my other article about GPU metrics for details). In this rules configuration, we are asking for new series of metrics — a ‘_current’ suffix will give us the present values, and ‘_over_time’ prefix gives us pod metrics averaged over three minutes. You can of course play with this configuration and come up with something that suits your purpose. Note that we commented out the default rule.</p><pre>rules:<br>  #default: true<br>  custom: <br>    - seriesQuery: &#39;{UUID!=&quot;&quot;}&#39;<br>      resources:<br>        overrides:<br>          node: {resource: &quot;node&quot;}<br>          exported_pod: {resource: &quot;pod&quot;}<br>          exported_namespace: {resource: &quot;namespace&quot;}<br>      name:<br>        matches: ^DCGM_FI_(.*)$<br>        as: &quot;${1}_over_time&quot;<br>      metricsQuery: ceil(avg_over_time(&lt;&lt;.Series&gt;&gt;{&lt;&lt;.LabelMatchers&gt;&gt;}[3m]))<br>    - seriesQuery: &#39;{UUID!=&quot;&quot;}&#39;<br>      resources:<br>        overrides:<br>          node: {resource: &quot;node&quot;}<br>          exported_pod: {resource: &quot;pod&quot;}<br>          exported_namespace: {resource: &quot;namespace&quot;}<br>      name:<br>        matches: ^DCGM_FI_(.*)$<br>        as: &quot;${1}_current&quot;<br>      metricsQuery: &lt;&lt;.Series&gt;&gt;{&lt;&lt;.LabelMatchers&gt;&gt;}<br>  existing:<br>  external: []</pre><p>Save this file, go one folder level back and install the adapter.</p><pre>cd ..</pre><pre>helm install prometheus-adapter prometheus-adapter/ -n kube-system</pre><p>Verify the adapter pod.</p><pre>$ kubectl get pods -n kube-system|grep prometheus</pre><pre>prometheus-adapter-fd8ccb5b7-5lhsm                        1/1     Running   0          2m</pre><p>Now is the time to actually run a program that stresses GPU and see if it gets scaled automatically.</p><h3>HPA target for scaling</h3><p>Create a yaml file, say, gpu-ray-autoscaler.yaml with the following content.</p><pre>---<br>apiVersion: autoscaling/v2beta1<br>kind: HorizontalPodAutoscaler<br>metadata:<br>  name: hpa-gpu<br>  namespace: rayexperiment<br>spec:<br>  scaleTargetRef:<br>    apiVersion: apps/v1beta1<br>    kind: Deployment<br>    name: ray-worker<br>  minReplicas: 1<br>  maxReplicas: 4<br>  metrics:<br>   - type: Pods<br>     pods:<br>       # use the metric that you used above: pods/http_requests<br>       metricName: DEV_GPU_UTIL_current<br>       targetAverageValue: 40</pre><p>We are targeting the Deployment called ray-worker which we are going to create later on. Remember the metrics we created — we are using one of them DEV_GPU_UTIL_current. If GPU usage goes above forty percent, a new ray-worker pod is created, with four maximum replicas. We can also add other GPU metrics if we want to. Now let’s deploy this autoscaler. Note that we are usingrayexperiment namespace.</p><pre>kubectl create -f gpu-ray-autoscaler.yaml -n rayexperiment</pre><h4>GPU workload</h4><p>Sure we can create an actual ML / deep learning workload to exercise GPU and autoscaler, but let’s stick to a simple one for now. Let’s create a ray python program that stresses GPU with a simulated load. We will then create a docker container out of it and use it in a ray cluster.</p><p>This is a simple Ray program that stresses GPU. A simple function that simulates high GPU load for five minutes, called ten times in a loop. Ray-enabling is as easy as decorating the method to be remote and calling it appropriately. I also added a ray.wait on the distributed executions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36e753e6189369507e00ed61dd165813/href">https://medium.com/media/36e753e6189369507e00ed61dd165813/href</a></iframe><p>This is requirements.txt file is a one liner for this with just — torch==1.6.0 . We will be using a ray base image that has all the other necessary packages.</p><p>Our Dockerfile , ray’s gpu base image will contain the necessary cuda toolkit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4441c982d6dd3611b67959b3fd705f39/href">https://medium.com/media/4441c982d6dd3611b67959b3fd705f39/href</a></iframe><p>Our .dockerignore file for completeness. Note the ray cluster deployment yaml file, we are going to create next.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20db000226ec14c578ac4a6c10a34a6e/href">https://medium.com/media/20db000226ec14c578ac4a6c10a34a6e/href</a></iframe><p>Now let’s build that image and tag it.</p><pre>docker build -t ray-gpu-load .</pre><p>Push the image to the image repository currently used in your Kubernetes cluster.</p><pre>docker tag ray-gpu-load:latest &lt;your-docker-repo/your-namespace&gt;/ray-gpu-load:latest</pre><pre>docker push &lt;your-docker-repo/your-namespace&gt;/ray-gpu-load:latest</pre><h3>Ray cluster</h3><p>We have a ray cluster deployment yaml readily available from ray project. Let’s download it.</p><pre><a href="https://github.com/ray-project/ray/blob/master/doc/kubernetes/ray-cluster.yaml">https://github.com/ray-project/ray/blob/master/doc/kubernetes/ray-cluster.yaml</a></pre><p>We need to make a few changes to this file. We will need to use the image we just built and also ask for gpu resources. Let’s save this file as ray-cluster-gpuload.yaml after these changes.</p><p>For the ray-head section:</p><pre>containers:<br>        - name: ray-head<br>          image: &lt;your-docker-repo/your-namespace&gt;/ray-gpu-load:latest</pre><p>And also for the ray-worker section:</p><pre>containers:<br>      - name: ray-worker<br>        image: &lt;your-docker-repo/your-namespace&gt;/ray-gpu-load:latest</pre><p>Request for gpu resource in the ray-worker section.</p><pre>resources:<br>          requests:<br>            cpu: 1000m<br>            memory: 512Mi<br>          limits:<br>            cpu: 1000<br>            <strong>nvidia.com/gpu: 1</strong></pre><p><em>Note: You may need to add </em><em>imagePullSecrets depending on how you configured your cluster to pull docker images from the repository.</em></p><p>Change also the namespace in this yaml file to rayexperimentto match with what we have been doing so far.</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  <strong>namespace: rayexperiment</strong></pre><p>Let’s deploy ray cluster with our image.</p><pre>kubectl create -f ray-cluster-gpuload.yaml</pre><p>Check and find out our worker pod.</p><pre>$ kubectl get pods -n rayexperiment</pre><pre>NAME                          READY   STATUS    RESTARTS   AGE<br>ray-head-74c449cb64-l9gfc     1/1     Running   0          15s<br>ray-worker-85789d96d4-zvb6t   1/1     Running   0          15s</pre><h4>Load it</h4><p>Get into the ray worker pod.</p><pre>$ kubectl -n rayexperiment exec --stdin --tty ray-worker-85789d96d4-zvb6t -- /bin/bash</pre><pre>(base) ray@ray-worker-85789d96d4-zvb6t:/app$</pre><p>Run our program.</p><pre>(base) ray@ray-worker-85789d96d4-zvb6t:/app$ python3 ray_gpu_load.py </pre><pre>2021-07-30 07:38:45,374 INFO worker.py:655 -- Connecting to existing Ray cluster at address: 10.99.14.184:6379<br>(pid=91) starting iteration  0<br>(pid=104, ip=10.244.0.201) starting iteration  1</pre><h4>Watch it work</h4><p>Soon you can see our autoscaler in action with pods scaling up due to high GPU usage.</p><pre># kubectl get pods -n rayexperiment</pre><pre>NAME                          READY   STATUS    RESTARTS   AGE<br>ray-head-74c449cb64-l9gfc     1/1     Running   0          5m12s<br>ray-worker-85789d96d4-6bjwc   1/1     Running   0          113s<br>ray-worker-85789d96d4-7tn68   1/1     Running   0          83s<br>ray-worker-85789d96d4-t8n77   1/1     Running   0          113s<br>ray-worker-85789d96d4-zvb6t   1/1     Running   0          5m12s</pre><p>If you had configured Grafana, you can visualize the metrics using standard NVIDIA DCGM dashboard. (You can refer to my earlier articles on how to configure this, if you haven’t already).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2wmAkSOGHZV4eOKabxN2uw.png" /></figure><p>After a few minutes, the program finishes and you can see the pod count go down along with GPU usage.</p><p>That’s it! We are now able to scale our ray programs based on GPU utilization metrics. You can replace this toy program with actual deep learning workloads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ba75d46b71b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to expose and visualize GPU metrics in your Kubernetes cluster]]></title>
            <link>https://medium.com/@rajupavuluri/how-to-expose-and-visualize-gpu-metrics-in-your-kubernetes-cluster-2520a7c3ba37?source=rss-ddf26189cbf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2520a7c3ba37</guid>
            <category><![CDATA[dashboard]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[nvidia]]></category>
            <category><![CDATA[gpu]]></category>
            <dc:creator><![CDATA[Raju Pavuluri]]></dc:creator>
            <pubDate>Thu, 29 Jul 2021 23:02:42 GMT</pubDate>
            <atom:updated>2021-07-29T23:02:42.037Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uoKyAHjqKi4kFEPpByoTSA.jpeg" /></figure><p>In the last article I wrote about how to get Docker and Kubernetes to recognize GPU nodes and use them. ML and deep learning programs need to be aware of GPU utilization, memory usage and perhaps temperature stats too during heavy training phases. Exposing GPU metrics so they can be monitored, needs some work. In this article I would like to share what I had to do in my Kubernetes cluster for GPU metrics monitoring.</p><p>My Kubernetes version is 1.20.2, and I have Tesla V100 GPUs . These instructions have been tried on rhel/centos7 .</p><p>Metrics monitoring is usually achieved by collection, storage and visualization. Prometheus (open source monitoring, time series database) along with Grafana for visualization is best suited for this purpose. You may have seen this architecture before, good to have a look at it again in this context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ktoezmb8yB1wTCukb53X0w.png" /></figure><p>We will install Prometheus stack for a monitoring solution. Then we will use NVIDIA’s Data Center GPU Manager (DCGM) to expose GPU metrics for Prometheus.</p><h4>Install Prometheus stack</h4><p>This is made easy by helm . We just need to make minor config additions while we install.</p><p>Add prometheus helm repository.</p><pre><strong>$ </strong>helm repo add prometheus-community <strong>\</strong><br>   https://prometheus-community.github.io/helm-charts</pre><p>update.</p><pre>$ helm repo update</pre><p>Now we will need to modify some settings. For this, we will inspect the chart get those values out in a file.</p><pre>helm inspect values prometheus-community/kube-prometheus-stack &gt; /tmp/kube-prometheus-stack.values</pre><p>Change the values so that we can expose the service via NodePort so we can access dashboards outside the cluster on a browser.</p><p>Look for this section in kube-prometheus-stack.values file.</p><pre>    ## Port to expose on each node<br>    ## Only used if service.type is &#39;NodePort&#39;<br>    ##<br>    nodePort: 30903<br>    ## List of IP addresses at which the Prometheus server service is available<br>    ## Ref: <a href="https://kubernetes.io/docs/user-guide/services/#external-ips">https://kubernetes.io/docs/user-guide/services/#external-ips</a><br>    ##</pre><pre>## Additional ports to open for Alertmanager service<br>    additionalPorts: []</pre><pre>externalIPs: []<br>    loadBalancerIP: &quot;&quot;<br>    loadBalancerSourceRanges: []<br>    ## Service type<br>    ##<br>    type: ClusterIP</pre><p>Change values for nodePort and type .</p><pre>nodePort: 30090</pre><pre>....</pre><pre>type: NodePort</pre><p>Look for serviceMonitorSelectorNilUsesHelmValues and change the value to false .</p><pre>## If true, a nil or {} value for prometheus.prometheusSpec.serviceMonitorSelector will cause the<br>    ## prometheus resource to be created with selectors based on values in the helm deployment,<br>    ## which will also match the servicemonitors created<br>    ##<br>    serviceMonitorSelectorNilUsesHelmValues: false</pre><p>Now search for additionalScrapeSettings — this should be empty by default. We will add a configMap to this section. After adding, it should look like this.</p><pre><strong>#</strong><em># AdditionalScrapeConfigs allows specifying additional Prometheus scrape configurations. Scrape configurations</em><br><strong>#</strong><em># are appended to the configurations generated by the Prometheus Operator. Job configurations must have the form</em><br><strong>#</strong><em># as specified in the official Prometheus documentation:</em><br><strong>#</strong><em># https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config. As scrape configs are</em><br><strong>#</strong><em># appended, the user is responsible to make sure it is valid. Note that using this feature may expose the possibility</em><br><strong>#</strong><em># to break upgrades of Prometheus. It is advised to review Prometheus release notes to ensure that no incompatible</em><br><strong>#</strong><em># scrape configs are going to break Prometheus after the upgrade.</em><br><strong>#</strong><em>#</em><br><strong>#</strong><em># The scrape configuration example below will find master nodes, provided they have the name .*mst.*, relabel the</em><br><strong>#</strong><em># port to 2379 and allow etcd scraping provided it is running on all Kubernetes master nodes</em><br><strong>#</strong><em>#</em><br>additionalScrapeConfigs:<br>- job_name: gpu-metrics<br>  scrape_interval: 1s<br>  metrics_path: /metrics<br>  scheme: http<br>  kubernetes_sd_configs:<br>  - role: endpoints<br>    namespaces:<br>      names:<br>      - gpu-operator-resources<br>  relabel_configs:<br>  - source_labels: [__meta_kubernetes_pod_node_name]<br>    action: replace<br>    target_label: kubernetes_node</pre><p>Now save this file. We are now ready to install Prometheus and Grafana. Note that we are creating a new namespace prometheus and installing to it.</p><pre><strong>$ </strong>helm install prometheus-community/kube-prometheus-stack <strong>\</strong><br>   --create-namespace --namespace prometheus \<br>   --generate-name \<br>   --values /tmp/kube-prometheus-stack.values</pre><p>You will see that the installation is successful. You can also verify by checking the pods.</p><pre>$ kubectl get pods -n prometheus</pre><pre>NAME                                                              READY   STATUS    RESTARTS   AGE<br>alertmanager-kube-prometheus-stack-1614-alertmanager-0            2/2     Running   0         2m<br>kube-prometheus-stack-1614-operator-5887789674-brbzf              1/1     Running   0         2m<br>kube-prometheus-stack-1614100923-grafana-6f6c5999f9-gspmp         2/2     Running   0         2m<br>kube-prometheus-stack-1614100923-kube-state-metrics-69bcc9zbj76   1/1     Running   0         2m<br>kube-prometheus-stack-1614100923-prometheus-node-exporter-6t9ln   1/1     Running   0         2m<br>kube-prometheus-stack-1614100923-prometheus-node-exporter-pp5pn   1/1     Running   0        2m<br>prometheus-kube-prometheus-stack-1614-prometheus-0                2/2     Running   0         2m</pre><p>You can also check the services to see prometheus is available at port 30090like we wanted.</p><pre>$ kubectl get svc -n prometheus</pre><pre>NAME                                                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE<br>alertmanager-operated                                       ClusterIP   None             &lt;none&gt;        9093/TCP,9094/TCP,9094/UDP   3m<br>kube-prometheus-stack-1614-alertmanager                     ClusterIP   10.97.150.200    &lt;none&gt;        9093/TCP                     3m<br>kube-prometheus-stack-1614-operator                         ClusterIP   10.107.120.24    &lt;none&gt;        443/TCP                      3m<br>kube-prometheus-stack-1614-prometheus                       NodePort    10.106.243.247   &lt;none&gt;        9090:30090/TCP               3m<br>kube-prometheus-stack-1614100923-grafana                    NodePort    10.100.30.205    &lt;none&gt;        80/TCP                 3m<br>kube-prometheus-stack-1614100923-kube-state-metrics         ClusterIP   10.111.133.205   &lt;none&gt;        8080/TCP                     3m<br>kube-prometheus-stack-1614100923-prometheus-node-exporter   ClusterIP   10.110.160.60    &lt;none&gt;        9100/TCP                     3m<br>prometheus-operated                                         ClusterIP   None             &lt;none&gt;        9090/TCP                     3m</pre><h4>Install DCGM Exporter</h4><p>This should be as easy with a helm install. However, if you go this route, not all the GPU metrics are enabled by default. One I was missing in particular was GPU utilization metric. So, I decided to clone the repository, and make a minor change to include the metric I wanted.</p><pre>git clone <a href="https://github.com/NVIDIA/gpu-monitoring-tools.git">https://github.com/NVIDIA/gpu-monitoring-tools.git</a></pre><p>Now edit default-counters.csv and dcp-metrics-include.csv files under gpu-monitoring-tools/etc/dcgm-exporter folder, to add metrics we want.</p><p>Look for DCGM_FI_DEV_GPU_UTIL tag under Utilization section in the csv file. Uncomment this line. While you are at it, you can comment any other metric else you don’t need in this file. Some of the metrics are computationally intensive to collect, so we should decrease the load on the system by commenting the unwanted metrics.</p><p>Now under the folder gpu-monitoring-tools/deployment , execute the following command to install dcgm-exporter.</p><pre>helm install — generate-name dcgm-exporter/</pre><p>You can look at the pods in the default name space for dcgm-exporter. Note that I have two GPU nodes in my cluster.</p><pre>$ kubectl get pods<br>NAME                             READY   STATUS      RESTARTS   AGE<br>dcgm-exporter-1615588874-l8pzq   1/1     Running     0          2m<br>dcgm-exporter-1615588874-sdj56   1/1     Running     0          2m</pre><h4>Prometheus dashboard</h4><p>Now let’s verify the GPU metrics exposed in Prometheus dashboard, by opening <em>http://&lt;machine-ip-address&gt;:30090</em> . You can type DCGM_GPU_UTIL in the box (or any other metric you are interested in) and see the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MYQpisdKED8YyhSaXDd8Qg.png" /></figure><h4>Configure Grafana</h4><p>Similar to what we did for prometheus dashboard, we can also change the default ClusterIP exposure that Grafana uses to NodePort , so we can access Grafana dashboards as well on a browser outside the cluster.</p><p>Let’s make a patch file.</p><pre><strong>$ </strong>cat &lt;&lt; EOF | tee grafana-patch.yaml<br>spec:<br>  type: NodePort<br>  nodePort: 32322<br>EOF</pre><p>Now patch the service up with this yaml. You will see a message saying the patch was successful.</p><pre><strong>$ </strong>kubectl patch svc kube-prometheus-stack-1603211794-grafana <strong>\</strong><br>   -n prometheus \<br>   --patch &quot;$(cat grafana-patch.yaml)&quot;</pre><p>Note down the external accessible port.</p><pre>$ kubectl get svc -n prometheus|grep grafana</pre><pre>kube-prometheus-stack-1614100923-grafana                    NodePort    10.100.30.205    &lt;none&gt;        80:32197/TCP                 3m</pre><p>In my case the port is 32197 . Open <em>http://&lt;machine-ip-address&gt;:32197</em> on your browser. You will be prompted for a login. You will use admin as the username. The password is available in the values file we changed before.</p><pre>$ cat /tmp/kube-prometheus-stack.values|grep -i password<br>  adminPassword: prom-operator</pre><h4>Grafana Dashboard</h4><p>We can use a DCGM dashboard made available by NVIDIA. To import that, in the Grafana page, go to <em>Dashboards -&gt; Manage -&gt; Import. </em>In the resulting page, add <a href="https://grafana.com/grafana/dashboards/12239"><em>https://grafana.com/grafana/dashboards/12239</em></a><em> </em>as url.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XnrcFLli6d87Rc05KFOENw.png" /></figure><p>Click Load and select Prometheus as data source. Once imported, you can watch the new dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E5ebz108g7P3gjIjAncchg.png" /></figure><p>We are done! You can of course create custom dashboards to visualize more metrics. In the next article we can see how to use these metrics to autoscale our workloads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2520a7c3ba37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to enable your Kubernetes cluster to use GPU nodes]]></title>
            <link>https://medium.com/@rajupavuluri/how-to-enable-your-kubernetes-cluster-to-use-gpu-nodes-1b2771b4a7f6?source=rss-ddf26189cbf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b2771b4a7f6</guid>
            <category><![CDATA[nvidia-docker]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Raju Pavuluri]]></dc:creator>
            <pubDate>Sun, 25 Jul 2021 23:20:49 GMT</pubDate>
            <atom:updated>2021-07-25T23:20:49.107Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lo0fkEZgInVh3mVHf6HGHg.jpeg" /></figure><p>Serious AI workloads, deep learning in particular, benefit from optimized multi processing offered by GPUs. Once you added GPU nodes to your Kubernetes cluster, getting it to recognize GPU resources is easy but requires you to follow a few steps. In this article I would like to share the experience of enabling my Docker and Kubernetes setup to work with GPU nodes. Hopefully this will make it easier for you, if you were to do this for your cluster. My Kubernetes version is 1.20.2, and I have Tesla V100 GPUs on my nodes. These instructions have been tried on rhel/centos7 .</p><p>Steps below that I describe, need to be followed for everyGPU node in your cluster.</p><h4>CUDA drivers</h4><p>If you haven’t already done so, make sure you have installed NVIDIA CUDA drivers on your GPU nodes. CUDA is a parallel computing platform from nvidia.</p><p><a href="https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html">1. Introduction - Installation Guide for Linux 12.9 documentation</a></p><p>After a successful installation, nvidia-smi command in a terminal should give you an output that looks similar to this. On this node I have two GPUs. Note that later versions of CUDA toolkit are available than what I have here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lb_hWvU10wJ5_I4ko2Nj-g.png" /></figure><h4>NVIDIA Container toolkit for Docker</h4><p>Next step is to install nvidia container toolkit for docker. Depending on the OS version you have, the instructions may differ slightly. If in doubt, you can always check <a href="https://docs.nvidia.com/datacenter/cloud-native/kubernetes/dcgme2e.html#install-nvidia-container-toolkit-previously-nvidia-docker2">NVIDIA documentation</a>.</p><pre>$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)</pre><pre>$ curl -s -L <a href="https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo">https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo</a> |  sudo tee /etc/yum.repos.d/nvidia-docker.repo</pre><pre>$ yum update</pre><pre>$ yum install -y nvidia-docker2</pre><p>We will need to change docker’s default container runtime to nvidia. We can do so by editing the file /etc/docker/daemon.json file and changing the value for default-runtime .</p><pre>{<br>    &quot;default-runtime&quot;: &quot;nvidia&quot;,<br>     &quot;runtimes&quot;: {<br>        &quot;nvidia&quot;: {<br>            &quot;path&quot;: &quot;/usr/bin/nvidia-container-runtime&quot;,<br>            &quot;runtimeArgs&quot;: []<br>        }<br>    }<br>}</pre><p>Time to restart docker for the changes to take effect.</p><pre>$ systemctl daemon-reload</pre><pre>$ systemctl restart docker</pre><p>Now we can test our docker environment by running a simple image provided by nvidia.</p><pre>$ docker run --rm -it nvcr.io/nvidia/cuda:10.2-base nvidia-smi</pre><p>You should see an output similar to this. As mentioned above, you can of course use docker images from nvidia with later versions of cuda toolkit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NswRV-Tj6NfM5NyE7wRGYg.png" /></figure><h4>NVIDIA Device Plugin for Kubernetes</h4><p>We verified that docker environment is successfully configured to support GPU accelerated containers. We just have one more step and we will be ready with our Kubernetes setup as well. Let us install NVIDIA Device Plugin so that our Kubernetes cluster can use GPUs.</p><p>Easiest way is to use helm to install this plugin. If you don’t have helm, it is simple to install. Go to your master node and execute the following command which should install helm.</p><pre><strong>$ </strong>curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 <strong>\</strong><br>   &amp;&amp; chmod 700 get_helm.sh \<br>   &amp;&amp; ./get_helm.sh</pre><p>You will see that helm is installed.</p><pre>Downloading <a href="https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz">https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz</a><br>Verifying checksum... Done.<br>Preparing to install helm into /usr/local/bin<br>helm installed into /usr/local/bin/helm</pre><p>We will add nvidia device plugin to helm repository.</p><pre><strong>$ </strong>helm repo add nvdp https://nvidia.github.io/k8s-device-plugin <strong>\</strong><br>   &amp;&amp; helm repo update</pre><p>Now let’s install the plugin.</p><pre><strong>$ </strong>helm install --generate-name nvdp/nvidia-device-plugin</pre><p>You can verify the installed plugin by checking the pods in kube-system namespace.</p><pre>$ kubectl get pods -n kube-system|grep -i nvidia</pre><pre>nvidia-device-plugin-daemonset-tl268                      1/1     Running   3          4h<br>nvidia-device-plugin-daemonset-v2dn8                      1/1     Running   8          4h</pre><h4>Put it to test</h4><p>Let us test our Kubernetes setup. To do so, let’s create a yaml deployment file, say, gpudemo-vectoradd.yaml with the following contents. We are using an nvidia cuda sample container that exercises GPU.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: gpu-demo-vectoradd<br>spec:<br>  restartPolicy: OnFailure<br>  containers:<br>  - name: cuda-vector-add<br>    image: &quot;nvidia/samples:vectoradd-cuda10.2&quot;<br>    resources:<br>      limits:<br>         nvidia.com/gpu: 1</pre><p>Deploy our yaml file.</p><pre>$ kubectl apply -f gpudemo-vectoradd.yaml</pre><p>Check for pods.</p><pre>$ kubectl get pods |grep gpu</pre><pre>gpu-demo-vectoradd               0/1     Completed   0          13s</pre><p>Check logs. It should look like this.</p><pre>$ kubectl logs gpu-demo-vectoradd</pre><pre>[Vector addition of 50000 elements]<br>Copy input data from the host memory to the CUDA device<br>CUDA kernel launch with 196 blocks of 256 threads<br>Copy output data from the CUDA device to the host memory<br>Test PASSED<br>Done</pre><p>We verified that our Kubernetes cluster is setup to run GPU accelerated containers! In the next article, let us see how we can expose and monitor these GPU metrics.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b2771b4a7f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Autoscaling Ray programs based on CPU metrics with HPA]]></title>
            <link>https://medium.com/@rajupavuluri/autoscaling-ray-programs-with-hpa-aa418cfc1f11?source=rss-ddf26189cbf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa418cfc1f11</guid>
            <category><![CDATA[rays]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[autoscaling]]></category>
            <dc:creator><![CDATA[Raju Pavuluri]]></dc:creator>
            <pubDate>Mon, 19 Jul 2021 20:32:58 GMT</pubDate>
            <atom:updated>2021-07-30T15:00:46.061Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KefUpgflMMiOGSjcNHI12g.jpeg" /></figure><p>Ray is an open source framework for building and running distributed applications, targeting large scale ML applications. With its universal and non-invasive API, it makes things so simple to scale your applications. Moreover, we can easily leverage Kubernetes cluster for executing these distributed Ray programs. In this article I will show you how I took advantage of Horizontal Pod Autoscaler on Kubernetes to scale Ray programs. Note that there are other ways of achieving the same, ray autoscaler for example — we will get to that in another article.</p><p>The Horizontal Pod Autoscaler automatically scales the number of pods based on CPU and memory utilization (or other custom metrics). The HPA fetches these metrics from a series of APIs provided by metrics-server . Depending on how you installed your Kubernetes cluster, this may not have been installed by default.</p><h4>Installing metrics-server</h4><pre>kubectl apply -f <a href="https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml">https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml</a></pre><p>If you would like to tweak any of the default values, you can download and edit this file before installing. For example, the metrics-resolution value determines how often metrics are scraped (not recommended to go below 15s)</p><pre>spec:</pre><pre>containers:</pre><pre>- args:</pre><pre>- --cert-dir=/tmp</pre><pre>- --secure-port=443</pre><pre>- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname</pre><pre>- --kubelet-use-node-status-port</pre><pre>- --metric-resolution=15s</pre><p>If you would like to aggressively scale down the pods, you can tweak the horizontal-pod-autoscaler-downscale-stabilization flag. The default is five minutes for a gradual scale down. To change this value, you need to edit /etc/kubernetes/manifests/kube-controller-manager.yaml file and add this flag. Note that going too low in this value may have undesirable effect on scaling down due to fluctuating metrics values. Save the file and the changed value should go into effect.</p><pre>spec:<br>  containers:<br>  - command:<br>    - kube-controller-manager</pre><pre>    - --horizontal-pod-autoscaler-downscale-stabilization=60s</pre><p>Now that we have the essential support from metrics-server let’s experiment with a toy Ray program that simulates CPU load and scale it. But first, let’s create an HPA target.</p><h4>HPA target</h4><p>Create a yaml file, say, ray-autoscaler.yaml with the following content.</p><pre>apiVersion: autoscaling/v1<br>kind: HorizontalPodAutoscaler<br>metadata:<br>  name: ray-autoscaler<br>spec:<br>  scaleTargetRef:<br>    apiVersion: apps/v1<br>    kind: Deployment<br>    name: ray-worker<br>  minReplicas: 1<br>  maxReplicas: 10<br>  targetCPUUtilizationPercentage: 40</pre><p>We are targeting the Deployment called ray-worker which we are going to create later on. If CPU usage goes above forty percent, a new ray-worker pod is created, with ten maximum replicas. We can also add memory utilization if we want to. Now let’s deploy this autoscaler. Note that the following command uses rayexperiment namespace.</p><pre>kubectl create -f ray-autoscaler.yaml -n rayexperiment</pre><p><strong>Docker container with simulated high CPU load</strong></p><p>Now let’s create a simple Ray program that loads up CPU. A small routine that simulates high cpu load for five minutes, called ten times in a loop. Note how easy it is to ray-enable this program. All I needed to do was to decorate the method to be ray.remote . I also added a ray.wait on the distributed executions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4dab62fd2c66b397abf69f1bed50307/href">https://medium.com/media/c4dab62fd2c66b397abf69f1bed50307/href</a></iframe><p>Let’s also make a docker image out of this, so we can load it onto ray pods. Our Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48797b4ab8c9019687642ec8aade7cd1/href">https://medium.com/media/48797b4ab8c9019687642ec8aade7cd1/href</a></iframe><p>Our .dockerignore file for completeness. Note the cluster deployment yaml file, we are going to create next.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5954de7a5f3d435dd80d4b374ff922a/href">https://medium.com/media/e5954de7a5f3d435dd80d4b374ff922a/href</a></iframe><p>Now let’s build that image and tag it.</p><pre>docker build -t rayexperiment/ray-cpu-load .</pre><h4>Ray cluster</h4><p>Time to use this image in a ray cluster. Fortunately deploying a ray cluster on Kubernetes is made super simple by this yaml file from ray project.</p><pre><a href="https://github.com/ray-project/ray/blob/master/doc/kubernetes/ray-cluster.yaml">https://github.com/ray-project/ray/blob/master/doc/kubernetes/ray-cluster.yaml</a></pre><p>We just need to make a tiny change in this file. Change the value forimage , wherever you see it in this file, to the docker image we just built. Let’s save this file as ray-cluster-cpuload.yaml after these changes.</p><p>For the ray-head section:</p><pre>containers:<br>        - name: ray-head<br>          image: rayexperiment/ray-cpu-load:latest</pre><p>And also for the ray-worker section:</p><pre>containers:<br>      - name: ray-worker<br>        image: rayexperiment/ray-cpu-load:latest</pre><p>Change also the namespace in this yaml file to rayexperimentto match with what we have been doing so far.</p><pre>kubectl create -f ray-cluster-cpuload.yaml</pre><p>Check and find out our worker pod.</p><pre>$ kubectl get pods -n rayexperiment<br>NAME                          READY   STATUS    RESTARTS   AGE<br>ray-head-6647466cc6-j78lf     1/1     Running   6          37m<br>ray-worker-6fd4459d64-bbvj4   1/1     Running   6          35m</pre><h4>Watch it work</h4><p>Get into the ray worker pod.</p><pre>$ kubectl -n realtimeai exec --stdin --tty ray-worker-6fd4459d64-bbvj4 -- /bin/bash</pre><p>Our cpu load program should be there. Let’s just run it.</p><pre>(base) ray@ray-worker-6fd4459d64-bbvj4:/app$ python3 ray_cpu_load.py <br>2021-07-19 11:40:11,775 INFO worker.py:655 -- Connecting to existing Ray cluster at address: 10.104.177.55:6379<br>(pid=84) starting iteration  0<br>(pid=126, ip=10.244.0.165) starting iteration  1<br>(pid=34, ip=10.244.0.168) starting iteration  2<br>(pid=34, ip=10.244.0.167) starting iteration  3<br>(pid=31, ip=10.244.0.169) starting iteration  4<br>(pid=40, ip=10.244.0.170) starting iteration  5<br>(pid=40, ip=10.244.0.171) starting iteration  6<br>(pid=34, ip=10.244.0.172) starting iteration  7<br>(pid=34, ip=10.244.0.173) starting iteration  8<br>(pid=34, ip=10.244.0.174) starting iteration  9</pre><p>You can see the iterations starting up, but let’s also monitor pod resource utilization simultaneously in another terminal window.</p><pre>watch kubectl top pods -n rayexperiment</pre><p>You can watch the pods scaling up.</p><pre>NAME                          CPU(cores)   MEMORY(bytes)<br>ray-head-6647466cc6-j78lf     1114m        455Mi<br>ray-worker-6fd4459d64-52nwb   1000m        179Mi<br>ray-worker-6fd4459d64-7v2cp   1001m        182Mi<br>ray-worker-6fd4459d64-8xzkr   1000m        174Mi<br>ray-worker-6fd4459d64-bbvj4   1000m        174Mi<br>ray-worker-6fd4459d64-bhkkn   1000m        176Mi<br>ray-worker-6fd4459d64-d4jg7   1001m        213Mi<br>ray-worker-6fd4459d64-gjkp9   17m          149Mi<br>ray-worker-6fd4459d64-hfxqx   1000m        175Mi<br>ray-worker-6fd4459d64-tb5lb   1001m        181Mi<br>ray-worker-6fd4459d64-wlbnt   998m         176Mi</pre><p>After a few minutes the program (and all the distributed executions) will finish and you can see the pods scaling down.</p><p>That’s it! We have a way of scaling up our Ray programs. Yes, this is just a toy program — but can easily be replaced with heavy hitting ML loads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa418cfc1f11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accessing Cloud Object Storage in Ray cluster]]></title>
            <link>https://medium.com/@rajupavuluri/accessing-cloud-object-storage-in-ray-cluster-55d6392dab08?source=rss-ddf26189cbf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/55d6392dab08</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud-object-storage]]></category>
            <category><![CDATA[rays]]></category>
            <category><![CDATA[persistent-volume]]></category>
            <dc:creator><![CDATA[Raju Pavuluri]]></dc:creator>
            <pubDate>Sun, 18 Jul 2021 02:30:13 GMT</pubDate>
            <atom:updated>2021-07-19T21:06:52.820Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pVSoPjNzlZbgpB-nEJpSSw.jpeg" /></figure><p>As I was experimenting with scaling my ML application on Kubernetes cluster, I came across Ray. Ray (<a href="https://ray.io/">https://ray.io/</a>) is a distributed execution framework for large-scale machine learning applications. While there are some alternatives available, Ray indeed lives up it’s ‘fast and simple distributed computing’ promise.</p><p>It turned out to be pretty easy to ‘ray-enable’ my ML application and scale it to my needs. We will get to that another time, but here I would like to share how I mounted my Cloud Object Storage as a volume available to my ray pods running on Kubernetes.</p><p>In a previous story (<a href="https://medium.com/@rpavuluri09/how-to-install-ibm-cloud-object-storage-kubernetes-plugin-e1d5828b825f">https://medium.com/@rajupavuluri/how-to-install-ibm-cloud-object-storage-kubernetes-plugin-e1d5828b825f</a>) I showed how to install IBM Cloud Object Storage Kubernetes plugin. This article assumes you have installed and verified the plugin. Let’s create an account on IBM Cloud, a Cloud Object Storage service instance and use it in our ray cluster.</p><p>Get a free account on IBM Cloud to try this out, following instructions at this link.</p><pre><a href="https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-provision#provision-account">https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-provision#provision-account</a></pre><p>Next, let’s provision a Cloud Object Storage service.</p><pre><a href="https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-provision#provision-instance">https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-provision#provision-instance</a></pre><p>Now that we have a service instance, we need to get some information so we can create a secret in our cluster. We need the apikey and service instance ID for this secret.</p><p>Follow the instructions here to get service credentials. Note down the apikey</p><pre><a href="https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-service-credentials">https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-service-credentials</a></pre><p>Now retrieve the GUID of the COS instance we just created.</p><pre><a href="https://cloud.ibm.com/docs/key-protect?topic=key-protect-retrieve-instance-ID">https://cloud.ibm.com/docs/key-protect?topic=key-protect-retrieve-instance-ID</a></pre><p>Let’s create that secret now that we have enough information to create out secret. Note that I am using ibm-cos-access as the secret name and using rayexperiment as my namespace.</p><pre>kubectl create secret generic ibm-cos-access — type=ibm/ibmc-s3fs — from-literal=api-key=&lt;api key retrieved from above&gt; — from-literal=service-instance-id=&lt;servie GUID retrieved from above&gt; -n rayexperiment</pre><p>Now that we have a way to connect to COS service, let’s create a Persistent Volume Claim (PVC). In your favorite editor, create a file, say, pvc.yaml, paste the following contents, and save it. Note that we are naming this PVC as cos-pvc. Note also that we are ‘auto-creating’ a bucket in COS storage.</p><pre>kind: PersistentVolumeClaim<br>apiVersion: v1<br>metadata:<br> name: cos-pvc<br> namespace: rayexperiment<br> annotations:<br>   ibm.io/auto-create-bucket: &quot;true&quot; # automatically create a bucket if it doesn&#39;t exist<br>   ibm.io/auto-delete-bucket: &quot;false&quot;<br>   ibm.io/auto_cache: &quot;true&quot;<br>   ibm.io/bucket: &quot;my-kube-bucket&quot;<br>   ibm.io/secret-name: &quot;ibm-cos-access&quot;<br>   ibm.io/endpoint: &quot;<a href="https://s3-api.dal-us-geo.objectstorage.service.networklayer.com/">https://s3-api.dal-us-geo.objectstorage.service.networklayer.com</a>&quot;<br>   ibm.io/region: &quot;us-standard&quot;<br>   volume.beta.kubernetes.io/storage-class: &quot;ibmc-s3fs-standard&quot;<br>   ibm.io/stat-cache-expire-seconds: &quot;&quot; # in seconds - default is no expire.<br>spec:<br> accessModes:<br>   - ReadWriteMany<br> resources:<br>   requests:<br>     storage: 100Gi # This value is fictitious, never used</pre><p>Now, let’s use it in a ray-cluster, but we need to create one! Fortunately, creating a ray-cluster in Kubernetes is as easy as downloading a yaml file from ray project.</p><pre><a href="https://github.com/ray-project/ray/blob/master/doc/kubernetes/ray-cluster.yaml">https://github.com/ray-project/ray/blob/master/doc/kubernetes/ray-cluster.yaml</a></pre><p>We will need to make slight modifications to this yaml file to mount our storage as a volume. Edit the downloaded ray-cluster.yaml file.</p><p>Under the deployment for ray-worker , in the spec-&gt;template-&gt;spec section, add a securityContext. These are essential privilege and access control settings for our mounted volume.</p><pre>spec:<br>  securityContext:<br>    fsGroup: 1000<br>    runAsUser: 1000</pre><p>To the spec-&gt;template-&gt;spec-&gt;volumes section under ray-worker , add a volume for COS storage bucket.</p><pre>volumes:<br>- name: cos-storage<br>  persistentVolumeClaim:<br>    claimName: cos-pvc</pre><p>Under the containers section for ray-worker , add a volume mount. Note that we will have our bucket available at /dev/cos directory.</p><pre>volumeMounts:<br>  - mountPath: /dev/cos<br>    name: cos-storage<br>    readOnly: false</pre><p>Save the yaml file and deploy it.</p><pre>kubectl create -f ray-cluster.yaml</pre><p>Check ray pods.</p><pre>$ kubectl create -f ray-cluster.yaml -n rayexperiment<br>NAME                          READY   STATUS    RESTARTS   AGE<br>ray-head-74fc6cb767-gwzvb     1/1     Running   0          96m<br>ray-worker-6f579bf76b-75hzs   1/1     Running   0          96m</pre><p>Get into the worker pod and check for our COS bucket volume.</p><pre>kubectl -n rayexperiment exec --stdin --tty ray-worker-6f579bf76b-75hzs -- /bin/bash</pre><p>Now check for the mounted volume.</p><pre>(base) ray@ray-worker-6f579bf76b-75hzs:/$ cd /dev/cos<br>(base) ray@ray-worker-6f579bf76b-75hzs:/dev/cos$</pre><p>The bucket got created automatically and it got mounted as a volume as well to our pod! This directory will be empty because we didn’t have anything in our bucket. Let’s create a file to test it out.</p><pre>(base) ray@ray-worker-6f579bf76b-75hzs:/dev/cos$ echo &quot;this is my ray experiment&quot; &gt;&gt;experiment.txt<br>(base) ray@ray-worker-6f579bf76b-75hzs:/dev/cos$ ls -lto<br>total 1<br>-rw-r--r--. 1 ray 52 Jul 17 19:15 experiment.txt<br>(base) ray@ray-worker-6f579bf76b-75hzs:/dev/cos$</pre><p>Exit out of the container. We can verify this file we just created from inside our pod, on IBM Cloud console for our COS service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8m-UmpVEOsZek6sTnTJUMQ.png" /></figure><p>We now have a ray cluster that can access data stored in IBM Cloud Object Storage.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55d6392dab08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to install IBM Cloud Object Storage Kubernetes Plugin]]></title>
            <link>https://medium.com/@rajupavuluri/how-to-install-ibm-cloud-object-storage-kubernetes-plugin-e1d5828b825f?source=rss-ddf26189cbf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1d5828b825f</guid>
            <category><![CDATA[plugins]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[ibm-cloud-object-storage]]></category>
            <dc:creator><![CDATA[Raju Pavuluri]]></dc:creator>
            <pubDate>Sat, 17 Jul 2021 21:56:20 GMT</pubDate>
            <atom:updated>2021-07-19T21:14:36.959Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a47vk3Gu_nkL-eu9lzOXRw.jpeg" /></figure><p>I was playing with an ML program on my Kubernetes cluster. The program was supposed to scale and score a ton of data. So the first question was where to store this data and how to access it in my cluster. There were several solutions out there — I wanted to try IBM Cloud Object Storage (COS) first. First step for me was to install a plugin that would enable my Kubernetes cluster to access COS data.</p><p>This tutorial has all the instructions needed to get IBM Cloud Object Storage plugin installed onto your Kubernetes cluster. This article assumes you have docker installed and have a Kubernetes cluster running. My version of Kubernetes cluster is 1.20.2. When I tried to install the plugin and required binaries, I had to make some changes to make the process work for my cluster as explained below.</p><p>As specified in the plugin documentation, IBM Cloud Object Storage plug-in is a Kubernetes volume plug-in that enables Kubernetes pods to access IBM Cloud Object Storage buckets. The plug-in has two components: a dynamic provisioner and a FlexVolume driver for mounting the buckets using s3fs-fuse on a worker node. So, we will install s3fs driver and build the provisioner for plugin installation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xcPJbJ1Uy9tiu3tcSrhxiQ.png" /><figcaption>COS architecture image from <a href="https://github.com/IBM/ibmcloud-object-storage-plugin">https://github.com/IBM/ibmcloud-object-storage-plugin</a></figcaption></figure><h4>Building s3fs binary</h4><p><strong>Note</strong>: These are instructions for <em>rhel/centos7</em>. For other versions of Linux, please visit <a href="https://github.com/s3fs-fuse/s3fs-fuse/wiki/Installation-Notes">https://github.com/s3fs-fuse/s3fs-fuse/wiki/Installation-Notes</a> to get installation instructions.</p><p>s3fs allows Linux to mount an S3 bucket via FUSE. While you can technically install s3fs using yum, I had trouble getting it to work that way. So, I chose to build the code and install it myself.</p><p>Install necessary pre-reqs.</p><pre>yum install gcc libstdc++-devel gcc-c++ fuse fuse-devel curl-devel libxml2-devel mailcap git automake make</pre><pre>yum install openssl-devel</pre><p>Now clone s3fs repository and build the binaries.</p><pre>git clone <a href="https://github.com/s3fs-fuse/s3fs-fuse">https://github.com/s3fs-fuse/s3fs-fuse</a></pre><pre>cd s3fs-fuse/</pre><pre>./autogen.sh</pre><pre>make</pre><pre>make install</pre><h4>Building a docker image with the plugin</h4><p>We are now going to build the actual plugin. Again, there are helm charts available to install this plugin, but it looks like they are customized for clusters running on the Cloud. So, if you have a cluster that you are running on your own, like I do in this case, I suggest you build the plugin, customize and install following these instructions. For this to work, go and glide are pre-requisites.</p><p>Install go following these instructions <a href="https://golang.org/doc/install">https://golang.org/doc/install</a></p><p>Install glide following these instructions <a href="https://glide.readthedocs.io/en/latest/">https://glide.readthedocs.io/en/latest/</a></p><p>Set GOPATH env variable in your linux terminal .</p><pre>export GOPATH=$HOME/go</pre><p>Clone the repository.</p><pre>mkdir -p $GOPATH/src/github.com/IBM</pre><pre>mkdir -p $GOPATH/bin</pre><pre>cd $GOPATH/src/github.com/IBM/</pre><pre>git clone <a href="https://github.com/IBM/ibmcloud-object-storage-plugin.git">https://github.com/IBM/ibmcloud-object-storage-plugin.git</a></pre><pre>cd ibmcloud-object-storage-plugin</pre><p>Build the provisioner and driver.</p><pre>make<br>make provisioner<br>make driver</pre><p>Verify that a docker image for the COS plugin is built.</p><pre>docker images|grep ibmcloud-object-storage-plugin</pre><p>Push the provisioner container image to the image repository currently used in your Kubernetes cluster.</p><pre>docker tag ibmcloud-object-storage-plugin:latest &lt;your-docker-repo/your-namespace&gt;/ibmcloud-object-storage-plugin:latest</pre><pre>docker push &lt;your-docker-repo/your-namespace&gt;/ibmcloud-object-storage-plugin:latest</pre><h4>Installation of the plugin</h4><p>These instructions are as documented in the plugin repo, but with some customization for it to work on our cluster.</p><p><strong>Make the driver binaries available on every worker node</strong></p><p>Make the driver binary that you just build above ibmc-s3fsavailable on every worker node, say, by copying under /tmp</p><p>Now on every worker node, execute the following commands to copy the driver binary ibmc-s3fs to Kubernetes plugin directory. Then restart kubelet for the changes to take effect.</p><pre>$ sudo mkdir -p /usr/libexec/kubernetes/kubelet-plugins/volume/exec/ibm~ibmc-s3fs</pre><pre>$ sudo cp /tmp/ibmc-s3fs /usr/libexec/kubernetes/kubelet-plugins/volume/exec/ibm~ibmc-s3fs</pre><pre>$ sudo chmod +x /usr/libexec/kubernetes/kubelet-plugins/volume/exec/ibm~ibmc-s3fs/ibmc-s3fs</pre><pre>$ sudo systemctl restart kubelet</pre><p><strong>Some changes to provisioner.yaml</strong></p><p>As I had mentioned earlier, this didn’t quite work right away. I needed to make some changes to provisioner yaml file.</p><p>Locate the provisioner.yamlfile in the plugin directory that you just built. It should be in the deploy sub folder. Open it in an editor.</p><p>Change the api version.</p><pre>apiVersion: apps/v1</pre><p>Add a selector under the spec section in the yaml file.</p><pre>selector:<br>    matchLabels:<br>      app: ibmcloud-object-storage-plugin</pre><p>Change the location of the plugin image under the containers section to where you pushed it to.</p><pre>containers:<br>        - name: ibmcloud-object-storage-plugin-container<br>          image: &lt;your-docker-repo/your-namespace&gt;/ibmcloud-object-storage-plugin:latest</pre><p>Add an image pull secret under spec section, if required (depending on how you normally pull images to your cluster).</p><pre>imagePullSecrets:<br>        - name: &lt;your-docker-image-pull-sercet&gt;</pre><p><strong>Create the provisioner</strong></p><pre>$ kubectl create -f deploy/provisioner-sa.yaml<br>$ kubectl create -f deploy/provisioner.yaml</pre><p><strong>Create the storage class</strong></p><pre>$ kubectl create -f deploy/ibmc-s3fs-standard-StorageClass.yaml</pre><p><strong>Verify the plugin installation</strong></p><pre>$ kubectl get pods -n kube-system | grep object-storage<br>  ibmcloud-object-storage-plugin-7c96f8b6f7-g7v98   1/1       Running   0          28s</pre><p><strong>Verify the storage class</strong></p><pre>$ kubectl get storageclass |grep s3<br> ibmc-s3fs-standard ibm.io/ibmc-s3fs</pre><p>Now you have IBM Cloud Object Storage plugin installed on your cluster. We will discuss the usage in the next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1d5828b825f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>