<p>I am writing a command line tool in Go which will perform an action based on the existence of a particular pod on a <code>k8s</code> cluster, in a specific namespace.</p>

<p>I could do via command line (shell) invocations within my <code>go</code> program something like </p>

<pre><code>kubectl get pods -n mynapespace l app=myapp
</code></pre>

<p>or in case I am not certain about the labels, something even less elegant as:</p>

<pre><code>kubectl get pods -n mynapespace | grep -i somepatternIamcertainabout
</code></pre>

<p>However, given that I am using the k8s native language (Go) I was wondering whether there might be a more Go native/specific way of making such an inquiry to the k8s api server, without resorting to shell invocations from within my cli tool.</p>

pkaramol
<p>The kubectl utility is just a convenience wrapper that talks to the Kubernetes API using bog standard HTTP. The Go standard library has a great <a href="https://golang.org/pkg/net/http/" rel="nofollow noreferrer">http package</a>. The perfect fit for what you're trying to accomplish.</p>

<p>In fact, you could just use <a href="https://github.com/kubernetes/client-go" rel="nofollow noreferrer">this official client package</a> from the Kubernetes project itself.</p>
