KubeAdm fails to configure - Unable to connect to the server: EOF - kubernetes

I am getting issue to configure K8S running kubeadm on ubuntu 18.06.
After performing kubeadm-init on master 1 node all goes well :
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join 172.40.0.10:6443 --token oormjp.gf43botx19purn13 --discovery-token-ca-cert-hash sha256:5e9c917221233fdae445640415fac123204f41d31d072cd06545055187c860e2
So I execute after following commands :
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
When I test kubeclt version, I get :
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"c27b913fddd1a6c480c229191a087698aa92f0b1", GitTreeState:"clean", BuildDate:"2019-02-28T13:37:52Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
Unable to connect to the server: EOF
When I want to install a CNI such as weave or Flannel I get :
Unable to connect to the server: EOF
Here is my yaml config file use by kubeadm :
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: stable
apiServer:
certSANs:
- "172.40.0.10"
controlPlaneEndpoint: "172.40.0.10:6443"
networking:
podSubnet: 10.244.0.0/16
172.40.0.10 : is a HAProxy server.
Can anyone help me to debug it?

using "flannel" pod network take a look for requirements and please run:
set /proc/sys/net/bridge/bridge-nf-call-iptables to 1 by running sysctl >net.bridge.bridge-nf-call-iptables=1 to pass bridged IPv4 traffic to iptablesโ€™
chains
You can find more information here.

Related

KIND and kubectl: The connection to the server localhost:8080 was refused - did you specify the right host or port?

I'm trying to use KIND to spin up my Kubernetes cluster and trying to use it with Kubectl but I'm stymied at the first hurdle
I set up a cluster using the following kind config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- hostPort: 80
containerPort: 80
Then I use kubectl
kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?
This makes sense because if I do docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9dcd3b6fd19d kindest/node:v1.17.11 "/usr/local/bin/entrโ€ฆ" 14 minutes ago Up 14 minutes 127.0.0.1:44609->6443/tcp kind-control-plane
What do I have to do to start the kubernetes API server and get the nodes on it?
I solve this issue with sudo chmod 0644 /etc/kubernetes/admin.conf and export KUBECONFIG=/etc/kubernetes/admin.conf
Most likely problem and the one that usually gets me is that you donโ€™t have a .kube directory with the right config in it. Try this:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Kubernetes: /usr/local/bin/kubectl is version 1.19.0, and is incompatible with Kubernetes 1.16.2

I am setting up Kubernetes for the first on my local machine using Minikube.
I installed kubectl on my local machine using:
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
However, when I run the command:
minikube start
I get the following error:
๐ŸŽ‰ minikube 1.12.3 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.12.3
๐Ÿ’ก To disable this notice, run: 'minikube config set WantUpdateNotification false'
๐Ÿ™„ minikube v1.5.2 on Ubuntu 18.04
๐Ÿ’ก Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
๐Ÿ”„ Starting existing virtualbox VM for "minikube" ...
โŒ› Waiting for the host to be provisioned ...
๐Ÿณ Preparing Kubernetes v1.16.2 on Docker '18.09.9' ...
๐Ÿ”„ Relaunching Kubernetes using kubeadm ...
โŒ› Waiting for: apiserver
๐Ÿ„ Done! kubectl is now configured to use "minikube"
โš ๏ธ /usr/local/bin/kubectl is version 1.19.0, and is incompatible with Kubernetes 1.16.2. You will need to update /usr/local/bin/kubectl or use 'minikube kubectl' to connect with this cluster
I don't seem to understand what the error means by:
โš ๏ธ /usr/local/bin/kubectl is version 1.19.0, and is incompatible with Kubernetes 1.16.2. You will need to update /usr/local/bin/kubectl or use 'minikube kubectl' to connect with this cluster
I can't remember installing minikube or Kubernetes before now on my local machine.
I finally figured it out what the issue was.
I ran the command kubectl version and I got the following output:
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0",
GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean",
BuildDate:"2020-08-26T14:30:33Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2",
GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean",
BuildDate:"2019-10-15T19:09:08Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
It showed me the date when I installed Kubernetes using minikube installer, which was sometime in 2019 when I was trying out Kubenetes initially.
Here's how I fixed it:
There are 2 solutions:
Solution 1
Uninstall older/previous versions of Kubernetes using minikube on the Linux machine:
minikube stop; minikube delete
docker stop (docker ps -aq)
rm -r ~/.kube ~/.minikube
sudo rm /usr/local/bin/localkube /usr/local/bin/minikube
systemctl stop '*kubelet*.mount'
sudo rm -rf /etc/kubernetes/
docker system prune -af --volumes
Or on Mac:
minikube stop; minikube delete &&
docker stop $(docker ps -aq) &&
rm -rf ~/.kube ~/.minikube &&
sudo rm -rf /usr/local/bin/localkube /usr/local/bin/minikube &&
launchctl stop '*kubelet*.mount' &&
launchctl stop localkube.service &&
launchctl disable localkube.service &&
sudo rm -rf /etc/kubernetes/ &&
docker system prune -af --volumes
Reinstall a new copy of minikube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb
And then run the command below to pull a new base image of Kubernetes:
minkube start
This pulls a new image of Kubernetes, and also configures kubectl to use minikube.
Solution 2:
Run the command below to downgrade kubectl to the same version as Kubenetes on the local machine:
minikube kubectl
This will install the kubectl compatible version for Kubernetes using minikube
That's all.
I hope this helps
Installing kubectl again solved my issue.
In my case there was no need to uninstall older version I just followed installation steps again and it worked for me.
Update the apt package index and install packages needed to use the Kubernetes apt repository:
sudo apt-get update
sudo apt-get install -y ca-certificates curl
If you use Debian 9 (stretch) or earlier you would also need to install apt-transport-https:
sudo apt-get install -y apt-transport-https
Download the Google Cloud public signing key:
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
Add the Kubernetes apt repository:
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
Update apt package index with the new repository and install kubectl:
sudo apt-get update
sudo apt-get install -y kubectl
I Hope this works for you too

The connection to the server localhost:8080 was refused - did you specify the right host or port? FAQ

I am new to kubernetes . I got the below error while interacting with the cluster kubectl get nodes .
ERROR:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
After search in the internet i fixed my issues .
#sudo cp /etc/kubernetes/admin.conf $HOME/
#sudo chown $(id -u):$(id -g) $HOME/admin.conf
#export KUBECONFIG=$HOME/admin.conf
Your kubectl is probably not referring to right kubeconfig file or the kubeconfig file does not right details.
When there is clear instructions by kubeadm init to execute following commands as an regular user, if you miss runing them you end up with issue reported.
To make kubectl work for your non-root user, run these commands, which are also part of the kubeadm init output:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should check back the logs at kubeadm init time and you will find similar as below asking to execute the command.
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a Pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Maybe you not set environment variables, try this:
export KUBERNETES_MASTER=http://MasterIP:8080
MasterIP is your Kubernetes master IP
Issue is with the use-context in kubectl command.Please check the same in kubeconfig file.

Cannot connect to Kubernetes api on AWS vm's

I have deployed Kubernetes using the link Kubernetes official page
I see that Kubernetes is deployed because in the end i got this
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join 172.16.32.101:6443 --token ma1d4q.qemewtyhkjhe1u9f --discovery-token-ca-cert-hash sha256:408b1fdf7a5ea5f282741db91ebc5aa2823802056ea9da843b8ff52b1daff240
when i do kubectl get pods it thorws this error
# kubectl get pods
The connection to the server 127.0.0.1:6553 was refused - did you specify the right host or port?
When I do see the cluster-info it says as follows
kubectl cluster-info
Kubernetes master is running at https://127.0.0.1:6553
But when i see the config it shows as follows
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRY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UDBDRU1GMzc4MklDa1kzMDBHZlFEWFhiODA5MXhmcytxUjFQbEhJSHZKOGRqV29jNApvdTJ1b2dHc2tGTDhGdXVFTTRYRjhSV0grZXpJRkRjV1JsZnJmVHErZ2s2aUs4dGpSTUNVc2lFNEI5QT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
**server: https://172.16.32.101:6443**
Even telnet shows that there is a process running on 6443 but not on 6553
how can change the port and how can I fix the issue??
Any help would be of great use
Thanks in advance.
It looks like your last kubectl config interferes with the previous clusters configurations.
It is possible to have settings for several different clusters in one .kube/config or in separate files.
But in some cases, you may want to manage only the cluster you've just created.
Note: After tearing down the exited cluster using kubeadm reset followed by initializing fresh cluster using kubeadm init, new certificates will be generated. To operate the new cluster, you have to update kubectl configuration or replace it with the new one.
To clean up old kubectl configurations and apply the last one, run the following commands:
rm -rf $HOME/.kube
unset KUBECONFIG
# Check if you have KUBECONFIG configured in profile dot files and comment or remove it.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
It gives you up-to-date configuration for the last cluster you've created using kubeadm tool.
Note: You should copy kubectl configuration for all users accounts which you are going to use to manage the cluster.
Here are some examples of how to manage config file using the command line.
I figured out the issue it is because of the firewall in the machine I could join nodes to the cluster once I allowed traffic via port 6443. I didn't fix the issue with this post but for beginners use this K8's on AWS for a better idea.
Thanks for the help guys...!!!

Kubernetes Fission setup fails

I am trying to install Fission on a Kubernetes Cluster. When I ran:
helm install --namespace fission https://github.com/fission/fission/releases/download/0.4.1/fission-all-0.4.1.tgz
I gave some errors:
E0218 09:14:41.578967 3357 portforward.go:331] an error occurred forwarding 36281 -> 44134: error forwarding port 44134 to pod b29ecdfb514ada5583e99e416d3fc07e25d5bcf71206b450a1f4f972a9d2502b, uid : exit status 1: 2018/02/18 09:14:41 socat[26057] E connect(5, AF=2 127.0.0.1:44134, 16): Connection refused
Error: transport is closing
How can I fix these errors and install Fission?
My Cluster OS is Debian 9 and Kubernetes version is:
kubeadm version: &version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.3", GitCommit:"", GitTreeState:"clean", BuildDate:"2018-02-07T11:55:20Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Update:
I solved the previous error and i could install Fission. but i have a new error. When i ran fission env create --name nodejs --image fission/node-env:0.4.1
i gave this error:
Failed to create environment: Post
http://178.162.203.65:31313/v2/environments: dial tcp 178.162.203.65:31313:
getsockopt: connection refused
Finally I own found the answer of the question. When I was installing the Kubernetes. Exactly After ran kubeadm init I must ran :
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Neither root nor none-root must ran the above command.(I don't know why)