<p>I've been working with a bunch of k8s clusters for a while, using kubectl from the command line to examine information.  I don't actually call kubectl directly, I wrap it in multiple scripting layers.  I also don't use contexts, as it's much easier for me to specify different clusters in a different way.  The resulting kubectl command line has explicit --server, --namespace, and --token parameters (and one other flag to disable tls verify).</p>

<p>This all works fine.  I have no trouble with this.</p>

<p>However, I'm now trying to use telepresence, which doesn't give me a choice (yet) of not using contexts to configure this.  So, I now have to figure out how to use contexts.</p>

<p>I ran the following (approximate) command:</p>

<pre><code>kubectl config set-context mycontext --server=https://host:port --namespace=abc-def-ghi --insecure-skip-tls-verify=true  --token=mytoken
</code></pre>

<p>And it said: "Context "mycontext " modified."</p>

<p>I then ran "kubectl config view -o json" and got this:</p>

<pre><code>{
    "kind": "Config",
    "apiVersion": "v1",
    "preferences": {},
    "clusters": [],
    "users": [],
    "contexts": [
        {
            "name": "mycontext",
            "context": {
                "cluster": "",
                "user": "",
                "namespace": "abc-def-ghi"
            }
        }
    ],
    "current-context": "mycontext"
}
</code></pre>

<p>That doesn't look right to me.</p>

<p>I then ran something like this:</p>

<pre><code>telepresence --verbose --swap-deployment mydeployment --expose 8080 --run java -jar target/my.jar -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n
</code></pre>

<p>And it said this:</p>

<pre><code>T: Error: Namespace 'abc-def-ghi' does not exist
</code></pre>

<p><strong>Update</strong>:</p>

<p>And I can confirm that this isn't a problem with telepresence.  If I just run "kubectl get pods", it fails, saying "The connection to the server localhost:8080 was refused". That tells me it obviously can't connect to the k8s server.  The key is my "set-context" command. It's obviously not working, and I don't understand what I'm missing.</p>

David M. Karr
<p>You don't have any clusters or credentials defined in your configuration. First, you need to define a cluster:</p>
<pre><code>$ kubectl config set-cluster development --server=https://1.2.3.4 --certificate-authority=fake-ca-file
</code></pre>
<p>Then something like this for the user:</p>
<pre><code>$ kubectl config set-credentials developer --client-certificate=fake-cert-file --client-key=fake-key-seefile
</code></pre>
<p>Then you define your context based on your cluster, user and namespace:</p>
<pre><code>$ kubectl config set-context dev-frontend --cluster=development --namespace=frontend --user=developer
</code></pre>
<p>More information <a href="https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/" rel="nofollow noreferrer">here</a></p>
<p>Your config should look something like this:</p>
<pre><code>$ kubectl config view -o json
{
    &quot;kind&quot;: &quot;Config&quot;,
    &quot;apiVersion&quot;: &quot;v1&quot;,
    &quot;preferences&quot;: {},
    &quot;clusters&quot;: [
        {
            &quot;name&quot;: &quot;development&quot;,
            &quot;cluster&quot;: {
                &quot;server&quot;: &quot;https://1.2.3.4&quot;,
                &quot;certificate-authority-data&quot;: &quot;DATA+OMITTED&quot;
            }
        }
    ],
    &quot;users&quot;: [
        {
            &quot;name&quot;: &quot;developer&quot;,
            &quot;user&quot;: {
                    &quot;client-certificate&quot;: &quot;fake-cert-file&quot;,
                    &quot;client-key&quot;: &quot;fake-key-seefile&quot;
            }
        }
    ],
    &quot;contexts&quot;: [
        {
            &quot;name&quot;: &quot;dev-frontend&quot;,
            &quot;context&quot;: {
                &quot;cluster&quot;: &quot;development&quot;,
                &quot;user&quot;: &quot;developer&quot;,
                &quot;namespace&quot;: &quot;frontend&quot;
            }
        }
    ],
    &quot;current-context&quot;: &quot;dev-frontend&quot;
}
</code></pre>
