Error while running kubectl commands - kubernetes

I have recently installed minikube and kubectl. However when I run kubectl get pods or any other command related to kubectl I get the error
Unable to connect to the server: unexpected EOF
Does anyone know how to fix this?I am using Ubuntu server 16.04.Thanks in advance.

The following steps can be used for further debugging.
Check the minikube local cluster status using minikube status command.
$: minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 172.0.x.y
If problem with kubectl configuratuion,then configure it using, kubectl config use-context minikube command.
$: kubectl config use-context minikube
Switched to context "minikube".
Check the cluster status, using kubectl cluster-info command.
$: kubectl cluster-info
Kubernetes master is running at ...
Heapster is running at ...
KubeDNS is running at ...
...
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Note: It can even be due to very simple reason: internet speed (it happend to me just now).

I have same problem too. I solved after change the server addr to localhost
apiVersion: v1
clusters:
- cluster:
certificate-authority: /var/lib/minikube/certs/ca.crt
server: https://localhost:8443 # check it
name: m01
...
users:
- name: m01
user:
client-certificate: /var/lib/minikube/certs/apiserver.crt
client-key: /var/lib/minikube/certs/apiserver.key

I think your kubernetes master is not setup properly. You can check that by checking the following services in master node are in active state and running.
etcd2.service
kube-apiserver.service Kubernetes API Server
kube-controller-manager.service Kubernetes Controller Manager
kube-scheduler.service Kubernetes Scheduler

Related

Failed to install metrics-server on minikube

I am trying to install metrics-server on my Kubernetes cluster. But it is not going to READY mode.
I am was installed metrics-server in this method
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
After installing i was tried some of those commands, kubectl top pods, kubectl top nodes. But i got an error
Error from server (ServiceUnavailable): the server is currently unable to handle the request (get pods.metrics.k8s.io)
Metrics server is failed to start
Enable metrics-server addon in minikube cluster.
Try the following commend.
minikube addons enable metrics-server

Kubectl port-forward not working with IBM Cluster

When I do Kubernetes port-forward with IBM cluster I get connection refused. I have access to other clusters like Azure Kubernetes Service and kubectl port-forward is working fine there. Also when I get a pod log using kubectl logs {pod_name} I get TLS handshake error but the other kubernetes commands like get pod and describe pod is working fine.

Not able to access application running on kubernetes pod (Using Docker-Desktop: Single-node cluster)

See below service is running:
and Below error i am getting while trying to access it:
Kubectl get pods:
Yaml files:
Service:
Deployment:
Check pod status if it's running or not.
Also, you can try with port-forwarding to POD
kubectl port-forward <POD name> 8086:8086 & open localhost:8086

minikube stops randomly and can't run kubectl command

Sometimes when Minikube is already running and I try to run any kubectl command (like kubectl get pods) I get this error:
Unable to connect to the server: dial tcp 192.168.99.101:8443
So I stop Minikube and start it again and all kubectl commands work fine, but then after a while if I try to run any kubectl command I get the same error as above.
If I type minikube ip I get 192.168.99.100. Why does kubectl try to connect to 192.168.99.101 (as mentioned in the error) when Minikube is running on 192.168.99.100?
Note that I'm very new to Kubernetes.
kubectl config get-contexts gives me this output:
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* minikube minikube minikube
This is minikube logs output https://pastebin.com/kb5jNRyW
This usually happens when the IP of your VM might be changed, and your minikube is pointing to the previous IP, You can check through minikube ip and then check the IP of the VM created, they will be different.
You can also try minikube status, your output will be :
minikube: Running
cluster: Stopped
kubectl: Misconfigured: pointing to stale minikube-vm.
To fix the kubectl context, run minikube update-context
You can try minikube update-context and if it doesn't run even then, try minikube start followed by minikube update-context, it won't download everything again, it will only start the VM if shut down.

Helm list tries to connect to localhost rather than Kubernetes

I have a Kubernetes cluster running. All pods are running. This is a windows machine with minikube on it.
However helm ls --debug gives following error
helm ls --debug
[debug] Created tunnel using local port: '57209'
[debug] SERVER: "127.0.0.1:57209"
Error: Get http://localhost:8080/api/v1/namespaces/kube-system/configmaps?labelSelector=OWNER%!D(MISSING)TILLER: dial tcp 127.0.0.1:8080: connect: connection refused
Cluster information
kubectl.exe cluster-info
Kubernetes master is running at https://135.250.128.98:8443
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
kubectl service
kubectl.exe get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h
Dashboard is accessible at http://135.250.128.98:30000
kube configuration:
apiVersion: v1
clusters:
- cluster:
certificate-authority: C:\Users\abc\.minikube\ca.crt
server: https://135.250.128.98:8443
name: minikube
contexts:
- context:
cluster: minikube
user: minikube
name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
user:
as-user-extra: {}
client-certificate: C:\Users\abc\.minikube\client.crt
client-key: C:\Users\abc\.minikube\client.key
Is there a solution? Most online resource says cluster is misconfigured. But not sure what is misconfigured and how to solve this error?
What worked for me when I was facing the same issue was changing automountServiceAccountToken to true.
Use the following command to edit the tiller-deploy
kubectl --namespace=kube-system edit deployment/tiller-deploy
And change automountServiceAccountToken to true
I've faced that problem and found an explanation on GitHub.
In this case, the preferable method to make it work is to rebuild the docker container with missing environment variable. These lines should build a new image:
cat << eof > Dockerfile
FROM gcr.io/kubernetes-helm/tiller:v2.3.1
ENV KUBERNETES_MASTER XX.XX.XX.XX:8080
eof
docker build -t tiller:latest .
Please substitute XX.XX.XX.XX with your Kubernetes Master IP address.