Skip to content

Error testing connection.KubernetesClientException.An error has occurred. when trying to connect with kubernetes cluster #7142

Open
@Anirudh-alb

Description

@Anirudh-alb

Current setup

(not proficient in kuberneres)
Host machine is MacOs Sequoia M4 pro
minikube cluster ws started with
minikube start --cpus=4 --memory=6100
A minikube cluster, Jenkins runs inside this minikube cluster as a deployment & it is running fine.
For service a NodePort was created followed by a
minikube service jenkins-service -n devops-tools --url
command to get a url to access jenkins from host machine.
Next a user is created , then Manage Jenkins -> Clouds -> Install plugin -> Kubernetes is installed -> Create a new cloud ->
Here is the cloud config

name: Kubernetes
Kubernetes URL 
https://kubernetes.default.svc.cluster.local:443

Kubernetes Namespace
devops-tools

Disable https certificate check
Enabled

Jenkins URL
http://jenkins-service.devops-tools.svc.cluster.local:8080

Jenkins Tunnel
http://jenkins-service.devops-tools.svc.cluster.local:50000

other stuff is kept default
for why these values are chosen is i used claude for debugging and these values seemed correct to me

Some logs that may help

kubectl describe pod -n devops-tools jenkins-8cc6659c6-p27b8

Name:             jenkins-8cc6659c6-p27b8
Namespace:        devops-tools
Priority:         0
Service Account:  jenkins-admin
Node:             minikube/192.168.49.2
Start Time:       Fri, 27 Jun 2025 11:01:31 +0530
Labels:           app=jenkins-server
                  pod-template-hash=8cc6659c6
Annotations:      <none>
Status:           Running
IP:               10.244.0.9
IPs:
  IP:           10.244.0.9
Controlled By:  ReplicaSet/jenkins-8cc6659c6
Init Containers:
  volume-mount-hack:
    Container ID:  docker://75b76c203eaaa6ca71ffe2e81ab85458b0042e136547f900537a799583fe00cb
    Image:         busybox
    Image ID:      docker-pullable://busybox@sha256:f85340bf132ae937d2c2a763b8335c9bab35d6e8293f70f606b9c6178d84f42b
    Port:          <none>
    Host Port:     <none>
    Command:
      sh
      -c
      chown -R 1000:1000 /var/jenkins_home
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Fri, 27 Jun 2025 11:01:35 +0530
      Finished:     Fri, 27 Jun 2025 11:01:35 +0530
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/jenkins_home from jenkins-data (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-csncj (ro)
Containers:
  jenkins:
    Container ID:   docker://f72287341f7af7687119029a98448403fed364c581281ff30874df3aa1a343a6
    Image:          jenkins/jenkins:2.504.2-lts-jdk21
    Image ID:       docker-pullable://jenkins/jenkins@sha256:2abbd073f06850c3c962eedaa10e7aa21c517db1e582ad8c89b83ecfb6cb7510
    Ports:          8080/TCP, 50000/TCP
    Host Ports:     0/TCP, 0/TCP
    State:          Running
      Started:      Fri, 27 Jun 2025 11:05:30 +0530
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     1
      memory:  2Gi
    Requests:
      cpu:        500m
      memory:     500Mi
    Liveness:     http-get http://:8080/login delay=90s timeout=5s period=10s #success=1 #failure=5
    Readiness:    http-get http://:8080/login delay=60s timeout=5s period=10s #success=1 #failure=3
    Environment:  <none>
    Mounts:
      /var/jenkins_home from jenkins-data (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-csncj (ro)
Conditions:
  Type                        Status
  PodReadyToStartContainers   True 
  Initialized                 True 
  Ready                       True 
  ContainersReady             True 
  PodScheduled                True 
Volumes:
  jenkins-data:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  jenkins-pv-claim
    ReadOnly:   false
  kube-api-access-csncj:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    Optional:                false
    DownwardAPI:             true
QoS Class:                   Burstable
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:                      <none>


➜  ~ kubectl describe serviceaccount -n devops-tools jenkins-admin         

Name:                jenkins-admin
Namespace:           devops-tools
Labels:              <none>
Annotations:         <none>
Image pull secrets:  <none>
Mountable secrets:   <none>
Tokens:              <none>
Events:              <none>
➜  ~ kubectl get rolebindings,clusterrolebindings --all-namespaces -o wide | grep jenkins

            clusterrolebinding.rbac.authorization.k8s.io/jenkins-admin                                                   ClusterRole/jenkins-admin                                                          104m                                                                                      devops-tools/jenkins-admin
➜  ~ kubectl describe service -n devops-tools jenkins-service

Name:                     jenkins-service
Namespace:                devops-tools
Labels:                   <none>
Annotations:              prometheus.io/path: /
                          prometheus.io/port: 8080
                          prometheus.io/scrape: true
Selector:                 app=jenkins-server
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.97.214.43
IPs:                      10.97.214.43
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  32000/TCP
Endpoints:                10.244.0.9:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Internal Traffic Policy:  Cluster
Events:                   <none>

➜  ~ kubectl exec -n devops-tools jenkins-8cc6659c6-p27b8 -- sh -c '
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
echo "Token exists: $(test -f /var/run/secrets/kubernetes.io/serviceaccount/token && echo "YES" || echo "NO")"
curl -k -H "Authorization: Bearer $TOKEN" https://kubernetes.default.svc.cluster.local:443/api/v1/namespaces | head -20 
'
Defaulted container "jenkins" out of: jenkins, volume-mount-hack (init)
Token exists: YES
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0{
  "kind": "NamespaceList",
  "apiVersion": "v1",
  "metadata": {
    "resourceVersion": "18122"
  },
  "items": [
    {
      "metadata": {
        "name": "default",
        "uid": "f35bf438-ac9c-4827-80d8-8a6fd97f7df8",
        "resourceVersion": "21",
        "creationTimestamp": "2025-06-26T12:54:18Z",
        "labels": {
          "kubernetes.io/metadata.name": "default"
        },
        "managedFields": [
          {
            "manager": "kube-apiserver",
            "operation": "Update",
100  5517    0  5517    0     0   952k      0 --:--:-- --:--:-- --:--:-- 1077k
curl: (23) Failed writing body
➜  ~ 

kindly help if possible

The full error
Error testing connection https://kubernetes.default.svc.cluster.local:443: io.fabric8.kubernetes.client.KubernetesClientException: An error has occurred.

Also i watched a couple of setup videos online, the official one from 4 years ago, why did that video errors had way more context then these errors?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions