Questions tagged [client-go]

208 questions
27
votes
3 answers

example of exec in k8s's pod by using go client

I want to use k8s go client to exec command in a pod. However I cannot find any example about this. So I read kubectl exec source code, and write code as below. And err = exec.Stream(sopt) always get an error without any message. Can anyone tell me…
JJBoooom
  • 293
  • 1
  • 3
  • 5
18
votes
2 answers

Using client-go to `kubectl apply` against the Kubernetes API directly with multiple types in a single YAML file

I'm using https://github.com/kubernetes/client-go and all works well. I have a manifest (YAML) for the official Kubernetes Dashboard: https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta4/aio/deploy/recommended.yaml I want to mimic…
Simon
  • 865
  • 1
  • 5
  • 15
14
votes
2 answers

How to use Kubernetes fieldSelector to query ownerReferences

Does Kubernetes GET API actually support fieldSelector parameter to query values of array fields? For example, I have a Pod like: apiGroup: v1 kind: Pod metadata: ownerReferences: - apiVersion: apps/v1 blockOwnerDeletion: true …
ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
14
votes
2 answers

How to Submit generic "runtime.Object" to Kubernetes API using client-go

I'm using AWS' EKS which is Kubernetes v1.10 and I'm using client-go v7.0.0. What I'm trying to do is parse a .yml file with multiple Kubernetes resource definitions in a file and submit those resources to the Kubernetes API. I can successfully…
aloisbarreras
  • 557
  • 6
  • 14
9
votes
3 answers

How to list all kubernetes objects with specific label using client-go

I want to execute equivalent of kubectl get all -l app=myapp -n mynamespace or kubectl label all -l version=1.2.0,app=myapp track=stable --overwrite using client-go I looked at dynamic package, but it seems like it needs GroupVersionResource, which…
8
votes
1 answer

How to list all pods in k8s cluster using client-go in golang program?

I want to list all pods in k8s cluster using client-go in go program. A go program that list all pods in k8s cluster using client-go?
Ajeet Rai
  • 91
  • 1
  • 1
  • 3
8
votes
2 answers

Kubernetes client-go creating services and enpdoints

I am looking for pointers on how to create/update services and endpoints using the client-go API. Can't seem to find any examples or documentation on how to do it. Thanks! Satish
Satish Mohan
  • 81
  • 1
  • 2
7
votes
1 answer

How do I delete k8s Jobs and its pods by client-go?

I tried to delete my jobs with a LabelSelector by client-go: cli.BatchV1().Jobs("default").Delete(context.TODO(), name, metav1.DeleteOptions{}) And the job was deleted successfully, but the pods of it didn't! If I delete this job by kubectl, the…
Reed Chan
  • 525
  • 6
  • 16
7
votes
2 answers

What's the best way to get notified when kubernetes Deployments change using the k8s.io/client-go library?

Context I'm writing a script that uses the k8s.io/client-go library (godocs here) to manipulate Deployments. In particular, I want to add a label selector to every Deployment in my cluster. Deployment label selectors are immutable. So my approach is…
David Xia
  • 5,075
  • 7
  • 35
  • 52
6
votes
1 answer

List deployments using apimachinery by the .spec.selector.matchLabels key

I want to list my deployments based on a key value pair found in the .spec.selector.matchLabels field. Doing so using the plain labels is easy, but I could not find a way to match / fetch the deployment that satisfies the condition that a certain…
pkaramol
  • 16,451
  • 43
  • 149
  • 324
6
votes
1 answer

Use client-go to simulate 'kubectl wait' for a pod to be ready

In bash scripts, I normally use 'kubectl wait' to block until a certain pod resource is ready, e.g. something similar to this: kubectl wait --for=condition=Ready --timeout=2m -n mynamespace pod -l myselector This works well because often times I…
DaveUK
  • 1,440
  • 3
  • 18
  • 31
6
votes
0 answers

Unable to decode an event from the watch stream: stream error: stream ID 3; INTERNAL_ERROR

I want to listen for add events that are deployments within my cluster,I use the client-go Watch Api,It works well at first, but after a short period of time, it will report an error. I have tried two API ways to listen the one way: func…
Aranya
  • 119
  • 1
  • 5
6
votes
2 answers

Fail to connect to kubectl from client-go - /serviceaccount/token: no such file

I am using golang lib client-go to connect to a running local kubrenets. To start with I took code from the example: out-of-cluster-client-configuration. Running a code like this: $ KUBERNETES_SERVICE_HOST=localhost KUBERNETES_SERVICE_PORT=6443 go…
shershen
  • 9,875
  • 11
  • 39
  • 60
5
votes
1 answer

How to delete all custom resources of a kind in k8s cluster (all namespaces) using client-go

I'm trying to delete resources of a particular kind in a k8s cluster using client-go. I'm using this code but it requires a specific namespace to be declared, but i want to delete this resource in all namespaces. u.SetName("test") …
aditya
  • 65
  • 5
5
votes
1 answer

How to use the Pod conditions array returned from the client-go API?

I'm using the client-go API in Go to access the list of Pods under a given controller (Deployment). While querying the list of pods belonging to it using the selector labels, you get an array of PodConditions -…
Inian
  • 80,270
  • 14
  • 142
  • 161
1
2 3
13 14