# Localhost:8080 was refused via Jenkins but works via manual execution in server

**URL:** <https://community.jenkins.io/t/localhost-8080-was-refused-via-jenkins-but-works-via-manual-execution-in-server/2307>\
**Category:** Ask a question\
**Tags:** question, minikube, kubernetes\
**Created:** [May 2, 2022, 4:12pm UTC](https://community.jenkins.io/t/localhost-8080-was-refused-via-jenkins-but-works-via-manual-execution-in-server/2307 "2022-05-02T16:12:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![souravmajumder](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@souravmajumder](https://community.jenkins.io/u/souravmajumder)\
**Post date:** [May 2, 2022, 4:12pm UTC](https://community.jenkins.io/t/localhost-8080-was-refused-via-jenkins-but-works-via-manual-execution-in-server/2307/1 "2022-05-02T16:12:30Z")

</div>

Dear All,

I am very new to Kubernetes and in the beginning days of learning it .So advance apology If mistaking with some technical terms here. I have a strange issue where i am getting error message as port 8080 is refused while I am running the command via jenkins but it works fine when I run manually.

Command ran:  
kubectl apply -f \<kubernetes\_deployment.yml\>

Error in jenkins:  
“delta”: “0:00:00.049013”, “end”: “2022-04-26 14:47:53.248479”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2022-04-26 14:47:53.199466”, “stderr”: “The connection to the server localhost:8080 was refused - did you specify the right host or port?”, “stderr\_lines”: [“The connection to the server localhost:8080 was refused - did you specify the right host or port?”], “stdout”: “”, “stdout\_lines”: }  
[WARNING]: Consider using ‘become’, ‘become\_method’, and ‘become\_user’ rather

## Jenkins Running on Ubuntu 18.04.6 LTS on Server 1

Jenkins Version:2.332.2  
Jenkins Server: Ubuntu 18.04.6 LTS

### Cluster information:

Kubernets running on server 2

Kubernetes version:  
Client Version: version.Info{Major:“1”, Minor:“23”, GitVersion:“v1.23.6”, GitCommit:“ad3338546da947756e8a88aa6822e9c11e7eac22”, GitTreeState:“clean”, BuildDate:“2022-04-14T08:49:13Z”, GoVersion:“go1.17.9”, Compiler:“gc”, Platform:“linux/amd64”}  
Server Version: version.Info{Major:“1”, Minor:“22”, GitVersion:“v1.22.6”, GitCommit:“07959215dd83b4ae6317b33c824f845abd578642”, GitTreeState:“clean”, BuildDate:“2022-03-30T18:28:25Z”, GoVersion:“go1.16.12”, Compiler:“gc”, Platform:“linux/amd64”}

Cloud being used: (put bare-metal if not on a public cloud) : Microsoft Azure

Installation method: Minikube

Host OS: Ubuntu 20.04.4 LTS

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [May 3, 2022, 6:11am UTC](https://community.jenkins.io/t/localhost-8080-was-refused-via-jenkins-but-works-via-manual-execution-in-server/2307/2 "2022-05-03T06:11:48Z")

</div>

> [@souravmajumder](#):
>
> put bare-metal if not on a public cloud)

This feels like a template or something, did you want to report a bug?

> [@souravmajumder](#):
>
> WARNING]: Consider using ‘become’, ‘become\_method’, and ‘become\_user’ rather

This feels like ansible

I’m really not sure what you are doing, let alone what the problem is, so no idea how to help.

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [May 3, 2022, 6:12am UTC](https://community.jenkins.io/t/localhost-8080-was-refused-via-jenkins-but-works-via-manual-execution-in-server/2307/3 "2022-05-03T06:12:12Z")

</div>

Hi there,

“it doesn’t work” is always hard to remote debug. Try to always include these 3 things.

1. what did you try? (Code samples, command lines, screenshots, videos, etc)
2. what did happen? (Error messages, description, outputs, stuff)
3. what did you expect to happen?

Otherwise, it’s hard for us to get into your context and you’ll have to have someone who is exactly knowledgeable come along.

---

<div class="post-metadata">

**Author:** ![souravmajumder](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@souravmajumder](https://community.jenkins.io/u/souravmajumder)\
**Post date:** [May 3, 2022, 6:29am UTC](https://community.jenkins.io/t/localhost-8080-was-refused-via-jenkins-but-works-via-manual-execution-in-server/2307/4 "2022-05-03T06:29:16Z")

</div>

Hi Gavin,

Thanks for commenting.  
Below is my YML content. As part of this I am deploying .war file to the clusters.

* * *

- hosts: localhost  
become: true  
become\_user: root

---

<div class="post-metadata">

**Author:** ![souravmajumder](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@souravmajumder](https://community.jenkins.io/u/souravmajumder)\
**Post date:** [May 3, 2022, 6:33am UTC](https://community.jenkins.io/t/localhost-8080-was-refused-via-jenkins-but-works-via-manual-execution-in-server/2307/5 "2022-05-03T06:33:46Z")

</div>

When I am commenting Kubernetes deployment and running the same command manually on my worker/slave node its working fine.  
Where as when I am running deployment to Kubernetes through Jenkins its not working .PFB the screenshot

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/3/39a9efe7c76732d6e391bf1c6354b5f5d111dde3.png)

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [May 3, 2022, 4:46pm UTC](https://community.jenkins.io/t/localhost-8080-was-refused-via-jenkins-but-works-via-manual-execution-in-server/2307/6 "2022-05-03T16:46:09Z")

</div>

Okay, then my guess as to the problem is that kubectl is trying to read $HOME/.kube/config, and that config says kubernetes is running on localhost:8080, but on the agent your sshing to, localhost:8080 isn’t kubernetes?

This isn’t really a jenkins issue, this is ansible/kubectl failing.

> [@souravmajumder](#):
>
> running the same command manually on my worker/agent node its working fine.

FYI, Proper term is agent

Generally when something works one place, and not the other place, its env variables related. I would recommend dumping your env where it works and where it doesn’t.

In this specific case, on a machine with no ~/.kube/config i get the same error

```auto
kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?

```
