# I'm trying to run a cloudquery k8s sync for an on-prem kubernetes cluster and it is failing

**URL:** <https://community.cloudquery.io/t/im-trying-to-run-a-cloudquery-k8s-sync-for-an-on-prem-kubernetes-cluster-and-it-is-failing/1199>\
**Category:** CloudQuery Plugins\
**Created:** [July 1, 2025, 3:34pm UTC](https://community.cloudquery.io/t/im-trying-to-run-a-cloudquery-k8s-sync-for-an-on-prem-kubernetes-cluster-and-it-is-failing/1199 "2025-07-01T15:34:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prabhanjali](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/prabhanjali/32/109_2.png) [@Prabhanjali](https://community.cloudquery.io/u/Prabhanjali)\
**Post date:** [July 1, 2025, 3:34pm UTC](https://community.cloudquery.io/t/im-trying-to-run-a-cloudquery-k8s-sync-for-an-on-prem-kubernetes-cluster-and-it-is-failing/1199/1 "2025-07-01T15:34:39Z")

</div>

Hi, I’m trying to run a cloudquery k8s sync for an on-prem kubernetes cluster and it is failing with below error. kindly I’ve given the source and destination yaml files that we have used for syncing cloudquery

**Command used:** cloudquery sync source.yml destination.yml --log-console --log-level error --log-format json

**source.yml**

```auto
kind: source
spec:
  name: "k8s"
  path: "cloudquery/k8s"
  version: "v6.1.2"
  registry: cloudquery
  destinations: ["postgresql"]
  tables: ["*"]
  spec:
    kubeconfig_path: "./kubeconfig.yaml"  
    contexts: []  

```

**destnation.yml**

```auto
kind: destination
spec:
  name: "postgresql"
  path: "cloudquery/postgresql"
  version: "v7.1.2"
  write_mode: "overwrite-delete-stale"
  migrate_mode: "safe"
  spec:
    connection_string: "postgresql://xxxxxxxx"

```

**Cloudquery CLI Version** : v5.20.5

**Error:**

```auto
{"level":"error","module":"cli","invocation-id":"xxxxxxxxx","grpc.code":"Internal","grpc.component":"server","grpc.error":"rpc error: code = Internal desc = failed to init plugin: failed to initialize client: failed to build k8s RES config for context \"default\": unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined","grpc.method":"Init","grpc.method_type":"unary","grpc.service":"cloudquery.plugin.v3.Plugin","grpc.start_time":"2025-07-01T19:49:30+05:30","grpc.time_ms":"5.058","message":"finished call","peer.address":"@","protocol":"grpc","time":"2025-07-01T14:19:30Z"}
Error: failed to sync v3 source k8s: failed to init source k8s: rpc error: code = Internal desc = failed to init plugin: failed to initialize client: failed to build k8s RES config for context "default": unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
{"level":"error","module":"cli","invocation-id":"=xxxxxxxx","error":"failed to sync v3 source k8s: failed to init source k8s: rpc error: code = Internal desc = failed to init plugin: failed to initialize client: failed to build k8s RES config for context \"default\": unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined","time":"2025-07-01T14:19:30Z","message":"exiting with error"}

```

Any quick help would be appreciated.

Thank you!!!

---

<div class="post-metadata">

**Author:** ![erez](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/erez/32/40_2.png) [@erez](https://community.cloudquery.io/u/erez)\
**Post date:** [July 1, 2025, 3:52pm UTC](https://community.cloudquery.io/t/im-trying-to-run-a-cloudquery-k8s-sync-for-an-on-prem-kubernetes-cluster-and-it-is-failing/1199/2 "2025-07-01T15:52:57Z")

</div>

Hi @Prabhanjali 👋 , based on the error this seems like an authentication issue.  
Can you verify you’ve configured access to k8s correctly?  
You can verify this by running `kubectl config view` to see the configuration and `kubectl get namespaces` to ensure authentication works.

Additionally the CLI and integrations versions you’re using are quite, latest CLI version is `6.21.0`, latest k8s version is `v7.9.4` and latest Postgres version is `v8.8.9`

---

<div class="post-metadata">

**Author:** ![erez](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/erez/32/40_2.png) [@erez](https://community.cloudquery.io/u/erez)\
**Post date:** [July 1, 2025, 3:56pm UTC](https://community.cloudquery.io/t/im-trying-to-run-a-cloudquery-k8s-sync-for-an-on-prem-kubernetes-cluster-and-it-is-failing/1199/3 "2025-07-01T15:56:32Z")

</div>

You can read more about k8s authentication in [Kubernetes Plugin documentation | CloudQuery](https://hub.cloudquery.io/plugins/source/cloudquery/k8s/latest/docs#overview-authentication) and about self hosting CloudQuery in [Deployment Overview | CloudQuery](https://cli-docs.cloudquery.io/docs/deployment/overview)

---

<div class="post-metadata">

**Author:** ![erez](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/erez/32/40_2.png) [@erez](https://community.cloudquery.io/u/erez)\
**Post date:** [July 1, 2025, 6:10pm UTC](https://community.cloudquery.io/t/im-trying-to-run-a-cloudquery-k8s-sync-for-an-on-prem-kubernetes-cluster-and-it-is-failing/1199/4 "2025-07-01T18:10:13Z")

</div>

Looking at the plugin’s code and the error you received, there should be an additional log warning `Failed to create k8s client, fallback to use the in-cluster config` with another error details on the initial connection attempt.  
Can you share the full sync logs (please redact any private information)?

---

<div class="post-metadata">

**Author:** ![satish\_thandra](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/satish_thandra/32/158_2.png) [@satish\_thandra](https://community.cloudquery.io/u/satish_thandra)\
**Post date:** [July 2, 2025, 8:43am UTC](https://community.cloudquery.io/t/im-trying-to-run-a-cloudquery-k8s-sync-for-an-on-prem-kubernetes-cluster-and-it-is-failing/1199/5 "2025-07-02T08:43:46Z")

</div>

Hi, It worked now.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![stefan](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/stefan/32/75_2.png) [@stefan](https://community.cloudquery.io/u/stefan)\
**Post date:** [July 2, 2025, 9:06am UTC](https://community.cloudquery.io/t/im-trying-to-run-a-cloudquery-k8s-sync-for-an-on-prem-kubernetes-cluster-and-it-is-failing/1199/6 "2025-07-02T09:06:22Z")

</div>


