Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl apply command does not work, gives connection refused error

when I am trying to setup pod network using the following

sudo kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml

I get this error, please help

unable to recognize "https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused

UPDATE: Doesn't seem to be a permission issue, unlike other question

like image 236
Jibin Mathew Avatar asked Jul 26 '18 09:07

Jibin Mathew


People also ask

How does kubectl apply command works?

The command set kubectl apply is used at a terminal's command-line window to create or modify Kubernetes resources defined in a manifest file. This is called a declarative usage. The state of the resource is declared in the manifest file, then kubectl apply is used to implement that state.

What does kubectl apply mean?

Kubectl apply apply manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster through running kubectl apply . This is the recommended way of managing Kubernetes applications on production. See Kubectl Book.

How do I know if kubectl is working?

By default, kubectl configuration is located at ~/. kube/config . If you see a URL response, kubectl is correctly configured to access your cluster. If you see a message similar to the following, kubectl is not configured correctly or is not able to connect to a Kubernetes cluster.

How do you set current context in kubectl?

What this says is that you can create or modify contexts in your kubeconfig file with the command kubectl config set-context. This command also accepts the name of the context to be changed (or --current if you want to change the current context), as well as --user, --cluster, and --namespace options.


1 Answers

Found that it's an issue with kubectl not being configured properly.

Fixed the issued by using the following commands for calico network(change accordingly for your network addon plugin)

sudo kubeadm init --pod-network-cidr=192.168.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

and then run

sudo kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml

and follow the rest accordingly

like image 183
Jibin Mathew Avatar answered Sep 20 '22 08:09

Jibin Mathew