jenkinsci / kubernetes-operator

Kubernetes native Jenkins Operator
https://jenkinsci.github.io/kubernetes-operator
Other
597 stars 233 forks source link

Rancher-desktop, KinD, minikube #856

Closed JCzz closed 1 year ago

JCzz commented 1 year ago

I have tried to install and run Jenkins-operator on "Rancher-desktop, KinD, minikube" - non is working.

Are you sure it is working, see the following, from: https://jenkinsci.github.io/kubernetes-operator/docs/getting-started/latest/installing-the-operator/

kubectl port-forward jenkins-example 8080:8080
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Handling connection for 8080
E0620 21:58:20.217119   91073 portforward.go:409] an error occurred forwarding 8080 -> 8080: error forwarding port 8080 to pod f1aa3bf652d89de88ed9d756203e2c877b00886e2053b651b7950038b62e9eb1, uid : failed to execute portforward in network namespace "/var/run/netns/cni-97336e32-59b0-cdfc-fd53-006d7a652ace": failed to connect to localhost:8080 inside namespace "f1aa3bf652d89de88ed9d756203e2c877b00886e2053b651b7950038b62e9eb1", IPv4: dial tcp4 127.0.0.1:8080: connect: connection refused IPv6 dial tcp6 [::1]:8080: connect: connection refused 
error: lost connection to pod
brokenpip3 commented 1 year ago

hei @JCzz very likely it's caused by https://github.com/jenkinsci/kubernetes-operator/issues/827, can you temporary try the helm chart installation method?

brokenpip3 commented 1 year ago

Also can you post the kubectl get pods and the operator logs here?

JCzz commented 1 year ago

Thanks

@brokenpip3

I get the same error using Helm:

kubectl port-forward jenkins-operator-84b6fbbcb4-nxzcp 8080:8080 -n jenkins-operator
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Handling connection for 8080
E0628 10:41:26.637595   10725 portforward.go:409] an error occurred forwarding 8080 -> 8080: error forwarding port 8080 to pod cbbba64dea7958c74b13728b4aec172f4da916252f682955bdd6c9027bc71793, uid : failed to execute portforward in network namespace "/var/run/netns/cni-82ed7430-3c1e-14dd-0544-bbc8fd9a620f": failed to connect to localhost:8080 inside namespace "cbbba64dea7958c74b13728b4aec172f4da916252f682955bdd6c9027bc71793", IPv4: dial tcp4 127.0.0.1:8080: connect: connection refused IPv6 dial tcp6 [::1]:8080: connect: connection refused 
Handling connection for 8080
E0628 10:41:26.644475   10725 portforward.go:347] error creating error stream for port 8080 -> 8080: EOF
error: lost connection to pod

FYI: Also when installing using Helm the secrets gets created in default namespace, even setting "-n jenkins-operator"

brokenpip3 commented 1 year ago

you are targeting the jenkins operator, you need to target the jenkins pod or the jenkins svc

JCzz commented 1 year ago

Thanks @brokenpip3

"jenkins-operator-84b6fbbcb4-nxzcp" is the pod?

kubectl get pods -n jenkins-operator
NAME                                READY   STATUS    RESTARTS   AGE
jenkins-operator-84b6fbbcb4-nxzcp   1/1     Running   0          9m38s

For services:

kubectl get svc -A
NAMESPACE     NAME                             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                  AGE
default       jenkins-operator-http-jenkins    ClusterIP   10.96.63.210   <none>        8080/TCP                 9m53s
default       jenkins-operator-slave-jenkins   ClusterIP   10.96.20.140   <none>        50000/TCP                9m53s
default       kubernetes                       ClusterIP   10.96.0.1      <none>        443/TCP                  11m
kube-system   kube-dns                         ClusterIP   10.96.0.10     <none>        53/UDP,53/TCP,9153/TCP   11m

The doc says:

helm install jenkins-operator jenkins/jenkins-operator -n jenkins-operator

NAME: jenkins-operator
LAST DEPLOYED: Wed Jun 28 10:37:18 2023
NAMESPACE: jenkins-operator
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
1. Watch Jenkins instance being created:
$ kubectl --namespace jenkins-operator get pods -w

2. Get Jenkins credentials:
$ kubectl --namespace jenkins-operator get secret jenkins-operator-credentials-jenkins -o 'jsonpath={.data.user}' | base64 -d
$ kubectl --namespace jenkins-operator get secret jenkins-operator-credentials-jenkins -o 'jsonpath={.data.password}' | base64 -d

3. Connect to Jenkins (actual Kubernetes cluster):
$ kubectl --namespace jenkins-operator port-forward jenkins-jenkins 8080:8080

Now open the browser and enter http://localhost:8080
JCzz commented 1 year ago

Thanks @brokenpip3

Are you/anyone able to show the steps when using a minikube, kinD, Rancher or any cluster

I did Minikube, Kind and Rancher:

  1. kind create cluster
  2. kubectl create namespace jenkins-operator
  3. helm repo add jenkins https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/chart
  4. helm install jenkins-operator jenkins/jenkins-operator -n jenkins-operator
  5. kubectl --namespace jenkins-operator get secret jenkins-operator-credentials-jenkins -o 'jsonpath={.data.user}' | base64 -d
  6. kubectl --namespace jenkins-operator get secret jenkins-operator-credentials-jenkins -o 'jsonpath={.data.password}' | base64 -d
  7. kubectl --namespace jenkins-operator port-forward jenkins-jenkins 8080:8080

Now open the browser and enter http://localhost:8080

Note: 5-6 is not working as I need to get the secret from default namespace 7 is not working as it gives the above error

Can you make it work using KinD cluster - it is the most easy way to recreate the scenario?

Please provide the steps Helm or yaml - thanks

brokenpip3 commented 1 year ago

5-6 are not working because if you not specify the jenkins pod will be create in the default namespace, could you try to run?

kubectl get pod -n default

7 is not working because you need to specify the default namespace since if the jenkins pod is in namespace default the svc will be there as well, so kubectl --namespace default port-forward jenkins-jenkins 8080:8080 should work there.

If you want instead to specify the jenkins pod and svc namespace you can set the ns via helm :

helm install xxx --set jenkins.namespace=foo jenkins/jenkins-operator
JCzz commented 1 year ago

I will get back to Helm, just an update on yaml - our team found that using yaml and adding this image:

quay.io/jenkins-kubernetes-operator/operator:v0.8.0-beta2 to kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/all-in-one-v1alpha2.yaml

Makes it not fail, but only 0/1 pod of get pods

kubectl get pod -n default
NAME                                READY   STATUS    RESTARTS   AGE
jenkins-example                     0/1     Running   0          27s
jenkins-operator-857467647b-lqkzz   1/1     Running   0          58m

logs

kubectl logs jenkins-example
+ '[' '' == true ']'
+ echo 'To print debug messages set environment variable '\''DEBUG_JENKINS_OPERATOR'\'' to '\''true'\'''
To print debug messages set environment variable 'DEBUG_JENKINS_OPERATOR' to 'true'
+ mkdir -p /var/lib/jenkins/init.groovy.d
+ cp -n /var/jenkins/init-configuration/createOperatorUser.groovy /var/lib/jenkins/init.groovy.d
+ mkdir -p /var/lib/jenkins/scripts
+ cp /var/jenkins/scripts/init.sh /var/lib/jenkins/scripts
+ chmod +x /var/lib/jenkins/scripts/init.sh
+ echo 'Installing plugins required by Operator - begin'
Installing plugins required by Operator - begin
+ cat
+ jenkins-plugin-cli --verbose --latest true -f /var/lib/jenkins/base-plugins.txt
brokenpip3 commented 1 year ago

you need to wait, the container was running for only 27s, jenkins will need around 1min at least to be fully up and running

JCzz commented 1 year ago

FYI, the following is working:

How to:

From: https://hub.docker.com/r/virtuslab/jenkins-operator Add image to: all-in-one-v1alpha2.yaml curl -O https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/all-in-one-v1alpha2.yaml image: virtuslab/jenkins-operator

From: https://hub.docker.com/r/jenkins/jenkins/tags Add image to jenkins_instance.yam: image: jenkins/jenkins:2.401.2-lts-jdk11

brokenpip3 commented 1 year ago

I'm glad you resolved this, now is working because we also updated the all-in-one manifests in the master, closing.