title: 1 Jenkins 2 clusters, agent connection issue on 2nd cluster
body: <p>I'm sitting with a new issue that you might also face soon. I need a little help if possible. I've spent about almost 2 working weeks on this.</p>
  <p>I have 2 possible solutions for my problem.</p>
  <p><strong>CONTEXT</strong></p>
  <p>I have 2 kubernetes clusters called FS and TC.
  The Jenkins I am using runs on TC.</p>
  <p>The slaves do deploy in FS from the TC Jenkins, however the slaves in FS would not connect to the Jenkins master in TC.</p>
  <p>The slaves make use of a TCP connection that requires a HOST and PORT. However, the exposed jnlp service on TC is HTTP (http:/jenkins-jnlp.tc.com/) which uses nginx to auto generate the URL.</p>
  <p>Even if I use</p>
  <ul>
  <li>HOST: jenkins-jnlp.tc.com</li>
  <li>PORT: 80</li>
  </ul>
  <p>It will still complain that it's getting serial data instead of binary data.</p>
  <p><a href="https://i.stack.imgur.com/Yf5xE.png" rel="nofollow noreferrer">The complaint</a></p>
  <p>For TC I made use of the local jnlp service HOST (jenkins-jnlp.svc.cluster.local) with PORT (50000). This works well for our current TC environment.</p>
  <p><strong>SOLUTIONS</strong></p>
  <p><strong>Solution #1</strong></p>
  <p>A possible solution would involve having a HTTP to TCP relay container running between the slave and master on FS. It will then be linked up to the HTTP url in TC (http:/jenkins-jnlp.tc.com/), encapsulating the HTTP connection to TCP (localhost:50000) and vice versa.</p>
  <p>The slaves on FS can then connect to the TC master using that TCP port being exposed from that container in the middle.</p>
  <p><a href="https://i.stack.imgur.com/cNVnM.png" rel="nofollow noreferrer">Diagram to understand better</a></p>
  <p><strong>Solution #2</strong></p>
  <p>People kept complaining and eventually someone made a new functionality to Jenkins around 20 Feb 2020. They introduced Websockets that can run over HTTP and convert it to TCP on the slave.</p>
  <p>I did set it up, but it seems too new and is not working for me even though the slave on FS says it's connected, it's still not properly communicating with the Jenkins master on TC. It still sees the agent/slave pod as offline.</p>
  <p>Here are the links I used</p>
  <ol>
  <li><a href="https://stackoverflow.com/questions/38729686/jenkins-how-to-configure-jenkins-behind-nginx-reverse-proxy-for-jnlp-slaves-to/39965700#39965700">Original post</a></li>
  <li><a href="https://www.jenkins.io/blog/2020/02/02/web-socket/" rel="nofollow noreferrer">Update note on Jenkins</a></li>
  <li><a href="https://github.com/jenkinsci/jep/blob/master/jep/222/README.adoc" rel="nofollow noreferrer">Details on Jenkins WebSocket</a></li>
  <li><a href="https://github.com/jenkinsci/docker-inbound-agent" rel="nofollow noreferrer">Jenkins inbound-agent github</a></li>
  <li><a href="https://hub.docker.com/r/jenkins/inbound-agent" rel="nofollow noreferrer">DockerHub jenkins-inbound-agent</a></li>
  </ol>
  <p><strong>CONCLUSION</strong></p>
  <p>After a lot of fiddling, research and banging my head on the wall, I think the only solution is solution #1. Problem with solution #1, a simple tool or service to encapsulate HTTP to TCP and back does not exist (that I know of, I searched for days). This means, I'll have to make one myself.</p>
  <p>Solution #2 is still too new, zero to none docs to help me out or make setting it up easy and seems to come with some bugs. It seems the only way to fix these bugs would be to modify both Jenkins and the jnlp agent's code, which I have no idea where to even start.</p>
  <p><strong>UPDATE #1</strong></p>
  <p>I'm halfway done with the code for the intermediate container. I can now get a downstream from HTTP to TCP, I just have to set up an upstream TCP to HTTP.</p>
  <p>Also considering the amount of multi-treading required to run a single central  docker container to convert the protocols. I figured on adding the the HTTP-to-TCP container as a sidecar to the Jenkins agent when I'm done.</p>
  <p>This way every time a slave spins up in a different cluster, it will automatically be able to connect and I don't have to worry about multiple connections. That is the theory, but obviously I want results and so do you guys.</p>