<p>I am new to Kubernetes. I just trying to create a tls secret using kubectl. My ultimate goal is deploy a keycloak cluster in kubernetes.</p>
<p>So I follow this <a href="https://www.youtube.com/watch?v=SJrvqQF6qA0&amp;list=LL&amp;index=1&amp;t=1117s" rel="nofollow noreferrer">youtube tutorial</a>. But in this tutorial doesn't mention how to generate my own tls key and tls cert. So to do that I use this documentation (<a href="https://www.linode.com/docs/guides/create-a-self-signed-tls-certificate/" rel="nofollow noreferrer">https://www.linode.com/docs/guides/create-a-self-signed-tls-certificate/</a>).</p>
<p>Then I could generate MyCertTLS.crt and MyKeyTLS.key</p>
<pre><b>gayan@Gayan</b>:<b>/srv</b>$ cd certs
<b>gayan@Gayan</b>:<b>/srv/certs</b>$ ls
MyCertTLS.crt  MyKeyTLS.key
</pre>
<p>To create secret key for the kubernetes, I ran this command</p>
<p><code>sudo kubectl create secret tls my-tls --key=&quot;MyKeyTLS.key&quot; --cert=&quot;MyCertTLS.crt&quot; -n keycloak-test </code></p>
<p>But It's not working, I got this error,</p>
<pre><b>gayan@Gayan</b>:<b>/srv/certs</b>$ sudo kubectl create secret tls my-tls --key=&quot;MyKeyTLS.key&quot; --cert=&quot;MyCertTLS.crt&quot; -n keycloak-test
[sudo] password for gayan:                 
error: failed to create secret Post &quot;http://localhost:8080/api/v1/namespaces/keycloak-test/secrets?fieldManager=kubectl-create&amp;fieldValidation=Strict&quot;: dial tcp 127.0.0.1:8080: connect: connection refused
</pre>
<p><B>Note</B>: <br>
MiniKube is Running...<br>
And Ingress Addon also enabled...<br>
I have created a namespace called keycloak-test.</p>
<pre><b>gayan@Gayan</b>:<b>/srv/keycloak</b>$ kubectl get namespaces
NAME                   STATUS   AGE
default                Active   3d19h
ingress-nginx          Active   119m
keycloak-test          Active   4m12s
kube-node-lease        Active   3d19h
kube-public            Active   3d19h
kube-system            Active   3d19h
kubernetes-dashboard   Active   3d19h
</pre>
<p>I am trying to fix this error. But I have no idea why I get this, looking for a solution from the genius community.</p>

Gayan Kodithuwakku
<p>In your examples, <code>kubectl get namespaces</code> works, but <code>sudo kubectl create secret</code> doesn't.</p>
<p>You don't need <code>sudo</code> to work with Kubernetes.  In particular, the connection information is stored in a <code>$HOME/.kube/config</code> file by default, but when you <code>sudo kubectl ...</code>, that changes the home directory and you can't find the connection information.</p>
<p>The standard Kubernetes assumption is that the cluster is remote, and so your local user ID doesn't really matter to it.  All that does matter is the Kubernetes-specific permissions assigned to the user that's accessing the cluster.</p>
