kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
146 stars 45 forks source link

How to set up a non-root user, to use the C API or k8s #154

Closed wcamellia closed 1 year ago

wcamellia commented 1 year ago

How to set up a non-root user, to use the C API or k8s? my "C api" and "k8s" can not work under the non-root user

ityuhui commented 1 year ago

What's the error message your program outputs ?

Is your program running out of kube cluster or in cluster ?

And do you configure the right kubernetes config (if your program runs out of kube cluster) ?

wcamellia commented 1 year ago

my k8s cluster deploy in "root" user, but i change into "admin" user , when i uese the c api in the non-root user,The error message my program outputs: "kubeyaml_load_kubeconfig(): Cannot open the file /root/.kube/config.[Permission denied] load_kube_config(): Cannot load the kubeconfig /root/.kube/config Cannot load kubernetes configuration."

ityuhui commented 1 year ago

Option 1:

cp /root/.kube/config /some/location/where/non-root/user/can/read/config
export KUBECONFIG=/some/location/where/non-root/user/can/read/config
# run your program

Option 2:

int rc = load_kube_config(&basePath, &sslConfig, &apiKeys, "/some/location/where/non-root/user/can/read/config"); 

Option 3:

mkdir ~admin/.kube
cp /root/.kube/config ~admin/.kube/

I prefer the option 3.

wcamellia commented 1 year ago

ok !thank you very much

brendandburns commented 1 year ago

Closing since the question is answered.