<p>I have been trying to install kubernetes in Oracle cloud server.<br />
I followed <a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/" rel="noreferrer">the kubernetes instruction</a>.</p>
<p>Output of  <code>kubectl config view</code> :</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://10.0.0.208:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: DATA+OMITTED
    client-key-data: DATA+OMITTED
</code></pre>
<p>Error when exucuting <code>sudo kubectl apply -f</code> :</p>
<pre><code>The connection to the server localhost:8080 was refused - did you specify the right host or port?
</code></pre>
<p>in addition, if I wanted to see the pods then came out another error message too.</p>
<p>Error when executing <code>kubectl get pods</code> :</p>
<pre><code>E1228 00:53:51.858542   44216 memcache.go:238] couldn't get current server API group list: Get &quot;https://10.0.0.208:6443/api?timeout=32s&quot;: x509: certificate signed by unknown authority (possibly because of &quot;crypto/rsa: verification error&quot; while trying to verify candidate authority certificate &quot;kubernetes&quot;)
Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of &quot;crypto/rsa: verification error&quot; while trying to verify candidate authority certificate &quot;kubernetes&quot;)
</code></pre>

<p><a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/troubleshooting-kubeadm/#tls-certificate-errors" rel="noreferrer">TLS certificate errors</a></p>
<p>The following error indicates a possible certificate mismatch.</p>
<pre><code># kubectl get pods

Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of &quot;crypto/rsa: verification error&quot; while trying to verify candidate authority certificate &quot;kubernetes&quot;)
</code></pre>
<ul>
<li><p>Verify that the <code>$HOME/.kube/config</code> file contains a valid certificate, and regenerate a certificate if necessary. The certificates in a kubeconfig file are base64 encoded. The <code>base64 --decode</code> command can be used to decode the certificate and <code>openssl x509 -text -noout</code> can be used for viewing the certificate information.</p>
</li>
<li><p>Unset the <code>KUBECONFIG</code> environment variable using:</p>
<p>unset KUBECONFIG</p>
</li>
</ul>
<p>Or set it to the default <code>KUBECONFIG</code> location:</p>
<pre><code>export KUBECONFIG=/etc/kubernetes/admin.conf
</code></pre>
<p>Another workaround is to overwrite the existing <code>kubeconfig</code> for the &quot;admin&quot; user:</p>
<pre><code>mv  $HOME/.kube $HOME/.kube.bak
mkdir $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
</code></pre>
<p>This error should only come up if you have <strong>no contexts configured in your client</strong> and <strong>Make sure you are executing the command from the right user</strong>. If you run <code>kubectl config view</code> and you get something like this:</p>
<pre><code>The connection to the server localhost:8080 was refused - did you specify the right host or port?
</code></pre>
<p>Refer to <a href="https://github.com/Hawaiideveloper/Infastructure-as-Code-Sample_Env/issues/15#issuecomment-811377749" rel="noreferrer">github link</a> &amp; <a href="https://discuss.kubernetes.io/t/the-connection-to-the-server-localhost-8080-was-refused-did-you-specify-the-right-host-or-port/1464" rel="noreferrer">Kubernetes community Forums</a> for more information to resolve your issue.</p>
