Remote Agent Can't Connect to Jenkins Controller (HELM)

Hello,

I have a local Kubernetes cluster with Jenkins installed using HELM chart, and it works perfectly to build my projects. My current problem is that I’m trying to add another Kubernetes cloud (AWS EKS), and after spinning the Jenkins agent on the remote cluster, it fails to connect to the controller even with WebSocket enabled.

INFO: Using /home/jenkins/agent/remoting as a remoting work directory
Mar 19, 2023 7:12:34 AM org.jenkinsci.remoting.engine.WorkDirManager setupLogging
INFO: Both error and output logs will be printed to /home/jenkins/agent/remoting
Mar 19, 2023 7:12:35 AM hudson.remoting.jnlp.Main$CuiListener error
SEVERE: Handshake error.
io.jenkins.remoting.shaded.jakarta.websocket.DeploymentException: Handshake error.
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.client.ClientManager$3$1.run(ClientManager.java:658)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.client.ClientManager$3.run(ClientManager.java:696)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.client.ClientManager$SameThreadExecutorService.execute(ClientManager.java:849)
	at java.base/java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:493)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:337)
	at hudson.remoting.Engine.runWebSocket(Engine.java:678)
	at hudson.remoting.Engine.run(Engine.java:499)
Caused by: io.jenkins.remoting.shaded.org.glassfish.tyrus.core.HandshakeException: Response code was not 101: 400.
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.client.TyrusClientEngine.processResponse(TyrusClientEngine.java:301)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.ClientFilter.processRead(ClientFilter.java:167)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.Filter.onRead(Filter.java:111)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.Filter.onRead(Filter.java:113)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.SslFilter.handleRead(SslFilter.java:402)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.SslFilter.processRead(SslFilter.java:365)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.Filter.onRead(Filter.java:111)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.Filter.onRead(Filter.java:113)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.TransportFilter$4.completed(TransportFilter.java:295)
	at io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.TransportFilter$4.completed(TransportFilter.java:279)
	at java.base/sun.nio.ch.Invoker.invokeUnchecked(Unknown Source)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishRead(Unknown Source)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(Unknown Source)
	at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(Unknown Source)
	at java.base/sun.nio.ch.EPollPort$EventHandlerTask.run(Unknown Source)
	at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
2023-03-19T07:12:35.244550207Z

I have already enabled WebSocket in the HELM values.

agent:
    websocket: true

Anything else I’m missing?

It seems like there is an issue with the handshake between the Jenkins agent and the controller running on the Kubernetes cluster. Here are a few things you can check:

  1. Make sure that the Jenkins controller is reachable from the agent’s network. You can try pinging the controller from the agent’s shell to verify this.
  2. Verify that the agent is configured correctly. You can check the Kubernetes pod logs to see if there are any errors or warnings. Make sure that the agent pod has access to the Kubernetes cluster, and that the necessary permissions are granted.
  3. Check the network policies and firewall rules in the Kubernetes cluster. Make sure that the agent pod is allowed to communicate with the controller. You can try temporarily disabling any network policies or firewalls to see if this resolves the issue.
  4. If the above steps don’t help, you can try increasing the log level for the Jenkins agent by adding the following line to your values.yaml file:
agent:
  arguments: -Djava.util.logging.config.file=/var/jenkins_home/log.properties

Then, create a log.properties file with the following content:

handlers=java.util.logging.ConsoleHandler
.level=ALL
java.util.logging.ConsoleHandler.level=ALL

This should enable verbose logging for the Jenkins agent, which may help you identify the root cause of the issue.

Hi, How you solve this error I also face same error my pods run on eks and jenkins runs on ec2.
Thanks