Kubernetes can not find the server via clean installation

11/27/2019

I have been trying to learn Kubernetes with Docker to run containers and manage them with Kubernetes.

I use this web-page for installations: https://kubernetes.io/docs/tasks/tools/install-kubectl/

I have my own Debian/Linux server machine that I want to build and configure Kubernetes.

After following the kubectl installation steps, I get an error like:

Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:23:11Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
Error from server (NotFound): the server could not find the requested resource

kubectl version --short:

Client Version: v1.16.3
Error from server (NotFound): the server could not find the requested resource

microk8s.kubectl version --short:

Client Version: v1.16.3
Server Version: v1.16.3

I have tried the local microk8s and used as microk8s.kubectl and with that installation, I was able to configure and even make the container work. However, the regular kubectl can not find the server. These two have different installations and different names, folders etc. I assume that one will not break or have any impact on the other one.

Edit: Based on the suggestion of Suresh, I did kubectl config view and the result is:

apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []

Does anyone have any idea how to solve this problem?

-- Sojimanatsu
docker
kubernetes

1 Answer

11/28/2019

microk8s.kubectl config view --raw > $HOME/.kube/config

If you already have kubectl installed and you want to use it to access the microk8s deployment you can export the cluster's config with accessing-kubernetes on microk8s

Microk8s put the kubeconfig file at different location.

To avoid colliding with a kubectl already installed and to avoid overwriting any existing Kubernetes configuration file, microk8s adds a microk8s.kubectl command, configured to exclusively access the new microk8s install. When following instructions online, make sure to prefix kubectl with microk8s.

microk8s.kubectl get nodes
microk8s.kubectl get services 
-- Suresh Vishnoi
Source: StackOverflow