Questions tagged [kubernetes-python-client]
93 questions
2
votes
0 answers
How to convert V1Ingress object to yaml file
I'm trying to convert v1Ingress object to standard yaml file. However comparing the saved file with it's manifest file using kubectl get ing example -o yaml shows different files. Any pointers to solve this
from kubernetes import client,…

user89978
- 97
- 1
- 7
2
votes
1 answer
How to create a job with postStart and preStop handlers by python kubernetes
In the create_namespaced_job method there is no parameter that exists to define preStop and postStart handlers.
V1Job create_namespaced_job(namespace, body, pretty=pretty, dry_run=dry_run, field_manager=field_manager)
Source.
So, how to add these…

shiva
- 186
- 6
2
votes
1 answer
What is the API equivalent for adding/deleting kubernetes annotations?
I'm trying to find the API equivalent of How to remove (delete) annotation in Kubernetes
to remove annotation for a service type in Python. Doing it from the command line works perfectly fine.
The latest kubernetes-client/python does not have any…

Inian
- 80,270
- 14
- 142
- 161
2
votes
1 answer
How can I specify ServiceAccount to be picked up by config.load_incluster_config() from kubernetes python sdk
I have an environment with multiple ServiceAccounts, and pod with access to Kubernetes api using kubernetes python sdk. Which account does the function load_incluster_config() pick up. Is there any way I can specify an account to be picked?
I have…

Rugved Mahamune
- 546
- 1
- 5
- 8
2
votes
1 answer
Copy file to Kubernetes Pod
I am trying to copy a binary file to Kubernetes pod using the following way. The script work if the file is text format but not for binary.
from kubernetes import client, config
try:
config.load_kube_config()
except TypeError:
…

Nidhin
- 628
- 7
- 16
2
votes
2 answers
Cannot patch Kubernetes custom resource from Python SDK
Trying to patch my custom resource to add extra element into an Array.
Works fine using kubectl:
kubectl patch my-resource default --type=json -p '[ { "op":"add", "path": "/spec/data/-", "value": "3342, 43243.343, 434343" } ]' -v 9
but can't make…

Andrey Kozichev
- 31
- 4
2
votes
1 answer
Delete Kubernetes resources using python client
I want to use the python client of K8s and delete some of the resources such as statefulset. I can delete the statefulset itself but Ks8 doesn't delete the running pods. I found some examples that they set propagation_policy="Foreground" in delete…

AVarf
- 4,481
- 9
- 47
- 74
2
votes
1 answer
Unable to exec in a pod using kubernetes-cli in Python even after using stream api
I am following the official documentation and to my surprise, the request just won't work.
I tried reading multiple questions and answers but in vain. I had set stream api to use but the error did not go away.
My code is:
from __future__ import…

Aviral Srivastava
- 4,058
- 8
- 29
- 81
1
vote
1 answer
kubernetes python api read_namespaced_pod_log returns http 400 with pod log as well in exception
I'm trying to fetch pod logs using Kubernetes python library. I'm testing on minikube, I have added configuration.assert_hostname = False
API used is: read_namespaced_pod_log
Below is an example code:
#!/usr/bin/python3
import requests
import…

3br10ee032
- 103
- 2
- 11
1
vote
1 answer
Docker Can't find kubernetes Config File
I'm trying to containerize a python application, where I used the Kubernetes package. My Dockerfile is:
FROM python:3.10.6
ADD App_pod.py .
ADD config.yml ~/.kube/config
RUN pip3 install requests beautifulsoup4
RUN pip3 install kubernetes
RUN…

Mahmoud Abdelhafez
- 11
- 1
1
vote
0 answers
How to bind local ports to Kubernetes pods for port forwarding using Kubernetes Python client?
I need to port forward to my pods from my local machine. It can be done easily with kubectl:
kubectl port-forward my_pod -n namespace --address 0.0.0.0 5000:5000
But I have to achieve this using Python client. I can get the socket to the remote…

jybsuper
- 179
- 2
- 10
1
vote
1 answer
Load kubect config file using Kubernetes Python client returns error: Invalid kube-config file
I wrote a service to retrieve some information from the Kubernetes cluster. Below is a snippet from the kubernetes_service.py file that works perfectly when I run it on my local machine.
from kubernetes.client.rest import ApiException
from…

Lucas Scheepers
- 505
- 6
- 24
1
vote
3 answers
Kubernetes python API get instances of CRD
I'm currently using the Python APIs for Kubernetes and I have to:
Retrieve the instance of a custom resource name FADepl.
Edit the value of that instance.
In the terminal, I would simply list all FADepls with kubectl get fadepl and then edit the…

texdade
- 72
- 10
1
vote
2 answers
Get Ingress gateway IP address using Kubernetes Python client
I am using the following kubectl command to get the Ingress host IP address after my Seldon Deployment is avaible.
kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
I would like to run the…

Yannick
- 59
- 7
1
vote
1 answer
Unable to connect GKE autopilot cluster from kubernetes python client
I have created an Autopilot cluster on GKE
I want to connect and manage it with Python Kubernetes Client
I am able to get the kubeconfig of cluster
I am able to access the cluster using kubectl on my local system using the command
gcloud container…

HERAwais
- 357
- 5
- 21