Error: Could not connect to Cloud Shell on port 8080 (deploying Jenkins in google kubernetes cloud)

8/10/2018

I have followed all the steps in this guide

and verified that they all completed successfully.

But when I get to the last part where I preview the application on port 8080 I get the error:

Error: Could not connect to Cloud Shell on port 8080.
Ensure your server is listening on port 8080 and try again.

I have also tried to change the port to 8084 but same result.

Any suggestions on how to debug/fix this?

Below the result of some of the last commands that I executed on my local machine using the locally installed gcloud client:

$ kubectl get pods
NAME                          READY     STATUS    RESTARTS   AGE
cd-jenkins-7c786475dd-bz7kj   1/1       Running   0          2m

$ printf $(kubectl get secret cd-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
********
$ export POD_NAME=$(kubectl get pods -l "component=cd-jenkins-master" -o jsonpath="{.items[0].metadata.name}")
$ kubectl port-forward $POD_NAME 8080:8080 >> /dev/null &
[1] 24685
$ echo $POD_NAME
cd-jenkins-7c786475dd-bz7kj
-- u123
jenkins
kubernetes

1 Answer

9/27/2019

Accessing Jenkins through your local machine:

You can run all kubectl commands within your local machine, but if you run kubectl port-forwarding in your local machine you will have to access the Jenkins page through this address http://localhost:8080/.

Accessing Jenkins through Google Cloud Console:

In the Google Cloud Console, on the top right menu just click on the following icon >_ (Activate Cloud Shell) then run the port-forwarding command:

export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=cd" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward $POD_NAME 8080:8080 >> /dev/null &

Now if you click on the icon Web preview -> Preview on port 8080 you should see the login page.

Just remember that the port is only forwarded while the kubectl process is running.

-- Ander
Source: StackOverflow