<p>There's apparently 2 methods one can use to leverage <code>tridentctl</code> to interact with a running Trident Pod in their Openshift/Kubernetes cluster.</p>

<h3>1. Server string</h3>

<p>The <code>tridentctl</code> CLI can be instructed to talk to whatever server you want remotely using the <code>-s</code> or <code>--server</code> argument. In this context you could use the approach of remote shelling into the Trident Pod and then directing it to interact with the local Trident Orchestrator daemon.</p>

<strong><em>For example</em></strong>

<pre><code>$ oc -n trident rsh trident-6bdbdbc5dd-l8qtr
Defaulting container name to trident-main.
Use 'oc describe pod/trident-6bdbdbc5dd-l8qtr -n trident' to see all of the containers in this pod.
/ #
</code></pre>

<p>Now to interact:</p>

<pre><code>/ # tridentctl -s 127.0.0.1:8000 get backend
+--------------------------+----------------+--------+---------+
|           NAME           | STORAGE DRIVER | ONLINE | VOLUMES |
+--------------------------+----------------+--------+---------+
| ontapnas_192.168.101.101 | ontap-nas      | true   |     389 |
+--------------------------+----------------+--------+---------+
/ #
</code></pre>

<h3>2. Creating a Bash Function</h3>

<p>To expand on the above method, one could construct a shell function or alias in Bash to streamline this interaction like so:</p>

<em>Openshift</em>

<pre><code>tridentctl () {
    oc rsh -t -n trident -c trident-main \
        $(oc get pods -n trident -l app=trident.netapp.io -o jsonpath="{.items[].metadata.name}") \
        tridentctl -s 127.0.0.1:8000 $*
}
</code></pre>

<em>Kubernetes</em>

<pre><code>tridentctl () {
    kubectl exec -t -n trident \
        $(kubectl get pods -n trident -l app=trident.netapp.io -o jsonpath="{.items[].metadata.name}") \
        -c trident-main -- tridentctl -s 127.0.0.1:8000 $*
}
</code></pre>

<p>With one of these functions set, you could then run the following command from your macOS system:</p>

<pre><code>$ tridentctl get storageclass -o json
{
  "items": [
    {
      "Config": {
        "version": "1",
        "name": "basic",
        "attributes": {
          "backendType": "ontap-nas"
        },
        "storagePools": null,
        "additionalStoragePools": null
      },
      "storage": {
        "ontapnas_192.168.101.101": [
          "NA_01_aggr1",
          "NA_01_aggr2"
        ]
      }
    }
  ]
}
</code></pre>

<strong><em>How it works</em></strong>

<p>The above function merely determines the name of the Pod within the <code>trident</code> namespace and then remotely executes the command <code>tridentctl</code> using the same method above (from method #1) of connecting to the locally running Trident Orchestrator daemon within the Pod using the <code>--server</code> string.</p>

<p>The advantage with one of these approaches is that you simply can use a function/alias to codify it.</p>

<strong><em>Caveats</em></strong>

<p>Keep in mind that with the above shell function/alias approach will not work with commands such as this:</p>

<pre><code>$ tridentctl create backend -f &lt;backend-file&gt;
</code></pre>

<p>because the files you'll be referencing with it, <code>-f &lt;backend-file&gt;</code>, will be local to the system where you'll be running the function/alias, but the <code>tridentctl</code> command will actually be executing within a Pod on another system. This Pod will not have access to your local system's filesystem.</p>

<p>Your only options in this situation will be to either copy the file into the Pod's <code>/tmp</code> filesystem and execute it from there or to redirect the contents of the file, <code>&lt;backend-file&gt;</code> through a pipe, (<code>|</code>), for example:</p>

<pre><code>$ cat &lt;backend-file&gt; | tridentctl create backend -f -
</code></pre>

CC BY-SA 4.0
2019-05-28T12:33:13.873Z
2019-08-30T13:54:26.983Z
2019-08-30T13:54:26.983Z
slm
<h3>Background</h3>

<p>We're currently using NetApps Trident PV (Persistent Volume) orchestrator to dynamically create volumes on our NetApp ONTAP clusters for Pods running within our Openshift/Kubernetes environment.</p>

<p><strong>NOTE:</strong> See links in the references section if you're unfamiliar with Trident + NetApp.</p>

<h3>1. Native Built CLI</h3>

<p>Most people will use the <a href="https://github.com/NetApp/trident/releases" rel="nofollow noreferrer">pre-built binary</a> but this will only run <code>tridentctl</code> on Linux. Previously we'd been using the <code>tridentctl</code> command natively on a Linux system to interact with the Trident controller running within our cluster. </p>

<p>However, I'd like a more native method to do this from macOS. Currently NetApp does not ship a prebuilt <code>tridentctl</code> binary to do this.</p>

<h3>2. Using Docker Image</h3>

<p>Previously we'd been using the <code>tridentctl</code> command natively on a Linux system to interact with the Trident controller running within our cluster. </p>

<p>Here's my Trident Pod:</p>

<pre><code>$ oc -n trident get pods
NAME                       READY     STATUS    RESTARTS   AGE
trident-6bdbdbc5dd-l8qtr   2/2       Running   14         6d
</code></pre>

<p>Remote shell into the Pod:</p>

<pre><code>$ oc -n trident rsh trident-6bdbdbc5dd-l8qtr
Defaulting container name to trident-main.
Use 'oc describe pod/trident-6bdbdbc5dd-l8qtr -n trident' to see all of the containers in this pod.
/ #
</code></pre>

<p>Attempt to run <code>tridentctl</code>:</p>

<pre><code>/ # tridentctl get backend
Error: could not find the Kubernetes CLI
/ #
</code></pre>

<h3>3. Other Methods</h3>

<p>I explored my options in vain but did not care for any of these:</p>

<ul>
<li>Build Trident from source</li>
<li>Construct a new Dockerfile based on the Trident Docker image</li>
<li>Roll my own Docker image with <code>tridentctl</code> + <code>kubectl</code></li>
</ul>

<h3>References</h3>

<ul>
<li><a href="https://netapp-trident.readthedocs.io/" rel="nofollow noreferrer">NetApp Trident Read the Docs</a></li>
<li><a href="https://netapp-trident.readthedocs.io/en/stable-v19.04/kubernetes/index.html" rel="nofollow noreferrer">Trident for Kubernetes (overview)</a></li>
<li><a href="https://github.com/NetApp/trident" rel="nofollow noreferrer">NetApp Trident (Github)</a></li>
</ul>

<kubernetes><openshift><storage><persistent-volumes>
Interacting with a Trident container (NetApp) via CLI within a Openshift/Kubernetes cluster?
slm
# Interacting with a Trident container (NetApp) via CLI within a Openshift/Kubernetes cluster?

(Asked by: username_0 on 2019-05-28)

Background
We're currently using NetApps Trident PV (Persistent Volume) orchestrator to dynamically create volumes on our NetApp ONTAP clusters for Pods running within our Openshift/Kubernetes environment.
NOTE: See links in the references section if you're unfamiliar with Trident + NetApp.
1. Native Built CLI
Most people will use the pre-built binary but this will only run tridentctl on Linux. Previously we'd been using the tridentctl command natively on a Linux system to interact with the Trident controller running within our cluster. 
However, I'd like a more native method to do this from macOS. Currently NetApp does not ship a prebuilt tridentctl binary to do this.
2. Using Docker Image
Previously we'd been using the tridentctl command natively on a Linux system to interact with the Trident controller running within our cluster. 
Here's my Trident Pod:
$ oc -n trident get pods
NAME                       READY     STATUS    RESTARTS   AGE
trident-6bdbdbc5dd-l8qtr   2/2       Running   14         6d

Remote shell into the Pod:
$ oc -n trident rsh trident-6bdbdbc5dd-l8qtr
Defaulting container name to trident-main.
Use 'oc describe pod/trident-6bdbdbc5dd-l8qtr -n trident' to see all of the containers in this pod.
/ #

Attempt to run tridentctl:
/ # tridentctl get backend
Error: could not find the Kubernetes CLI
/ #

3. Other Methods
I explored my options in vain but did not care for any of these:

Build Trident from source
Construct a new Dockerfile based on the Trident Docker image
Roll my own Docker image with tridentctl + kubectl

References

NetApp Trident Read the Docs
Trident for Kubernetes (overview)
NetApp Trident (Github)

**Tags:** kubernetes, openshift, storage, persistent-volumes


---

## 1 answers

### Answer by username_0 on 2019-05-28. Score: 1 | Accepted answer

There's apparently 2 methods one can use to leverage tridentctl to interact with a running Trident Pod in their Openshift/Kubernetes cluster.
1. Server string
The tridentctl CLI can be instructed to talk to whatever server you want remotely using the -s or --server argument. In this context you could use the approach of remote shelling into the Trident Pod and then directing it to interact with the local Trident Orchestrator daemon.
For example
$ oc -n trident rsh trident-6bdbdbc5dd-l8qtr
Defaulting container name to trident-main.
Use 'oc describe pod/trident-6bdbdbc5dd-l8qtr -n trident' to see all of the containers in this pod.
/ #

Now to interact:
/ # tridentctl -s 127.0.0.1:8000 get backend
+--------------------------+----------------+--------+---------+
|           NAME           | STORAGE DRIVER | ONLINE | VOLUMES |
+--------------------------+----------------+--------+---------+
| ontapnas_192.168.101.101 | ontap-nas      | true   |     389 |
+--------------------------+----------------+--------+---------+
/ #

2. Creating a Bash Function
To expand on the above method, one could construct a shell function or alias in Bash to streamline this interaction like so:
Openshift
tridentctl () {
    oc rsh -t -n trident -c trident-main \
        $(oc get pods -n trident -l app=trident.netapp.io -o jsonpath="{.items[].metadata.name}") \
        tridentctl -s 127.0.0.1:8000 $*
}

Kubernetes
tridentctl () {
    kubectl exec -t -n trident \
        $(kubectl get pods -n trident -l app=trident.netapp.io -o jsonpath="{.items[].metadata.name}") \
        -c trident-main -- tridentctl -s 127.0.0.1:8000 $*
}

With one of these functions set, you could then run the following command from your macOS system:
$ tridentctl get storageclass -o json
{
  "items": [
    {
      "Config": {
        "version": "1",
        "name": "basic",
        "attributes": {
          "backendType": "ontap-nas"
        },
        "storagePools": null,
        "additionalStoragePools": null
      },
      "storage": {
        "ontapnas_192.168.101.101": [
          "NA_01_aggr1",
          "NA_01_aggr2"
        ]
      }
    }
  ]
}

How it works
The above function merely determines the name of the Pod within the trident namespace and then remotely executes the command tridentctl using the same method above (from method #1) of connecting to the locally running Trident Orchestrator daemon within the Pod using the --server string.
The advantage with one of these approaches is that you simply can use a function/alias to codify it.
Caveats
Keep in mind that with the above shell function/alias approach will not work with commands such as this:
$ tridentctl create backend -f 

because the files you'll be referencing with it, -f , will be local to the system where you'll be running the function/alias, but the tridentctl command will actually be executing within a Pod on another system. This Pod will not have access to your local system's filesystem.
Your only options in this situation will be to either copy the file into the Pod's /tmp filesystem and execute it from there or to redirect the contents of the file,  through a pipe, (|), for example:
$ cat  | tridentctl create backend -f -


---

