Questions tagged [kubernetes-go-client]

client-go provides Go clients for talking to a kubernetes cluster.

https://github.com/kubernetes/client-go

128 questions
31
votes
1 answer

Kubernetes client-go: watch.Interface vs. cache.NewInformer vs. cache.NewSharedIndexInformer?

I need my Go app to monitor some resources in a Kubernetes cluster and react to their changes. Based on numerous articles and examples, I seem to have found a few ways to do it; however, I'm relatively new to Kubernetes, and they're described in…
akavel
  • 4,789
  • 1
  • 35
  • 66
24
votes
2 answers

How to get the current namespace in a Pod?

One way I could think of is to set an environment which value is the namespace of the Pod when defining the Pod. Getting the namespace dynamically without requiring changes for Pod will be better because it lessens the burden of constructing a Pod.…
flyer
  • 9,280
  • 11
  • 46
  • 62
21
votes
2 answers

Disabling network logs on Kubernetes when running kubectl exec

Runnning kubectl exec -it -- /bin/bash is printing a lot of trash of the shell: ) Data frame handling I0331 17:46:15.486652 3807 logs.go:41] (0xc4201158c0) Data frame received for 5 …
Arkon
  • 2,648
  • 6
  • 26
  • 46
15
votes
4 answers

How to use the kubernetes go-client to get the same Pod status info that kubectl gives

Using the kubernetes go-client (k8s.io/client-go/kubernetes), I know how to get pod.Status and I find the pod.Status.Phase useful (docs). For example, I can output the Pod Status Phase of all Pods using this: ... api := clientset.CoreV1() …
Tom
  • 14,041
  • 16
  • 64
  • 80
11
votes
2 answers

How to provide resource limits in kubernetes go client pod spec?

Spec: v1.PodSpec{ Containers: []v1.Container{ v1.Container{ Name: podName, Image: deploymentName, ImagePullPolicy: "IfNotPresent", Ports: …
mohd.gadi
  • 495
  • 1
  • 7
  • 15
9
votes
2 answers

Watch kubernetes pod status to be completed in client-go

I am creating a pod in k8 client go and making a watch to get notified for when the pod has completed so that i can read the logs of the pod. The watch interface doesnt seem to provide any events on the channel. Here is the code, how would I get…
mohd.gadi
  • 495
  • 1
  • 7
  • 15
9
votes
3 answers

How to deserialize Kubernetes YAML file

How can I deserialize a Kubernetes YAML file into an Go struct? I took a look into the kubectl code, but somehow I get an error for every YAML file: no kind "Deployment" is registered for version "apps/v1beta1" This is an MWE: package main import…
svenwltr
  • 17,002
  • 12
  • 56
  • 68
8
votes
2 answers

how to get status of a pod in kubernetes using go-client

I am trying to delete a pod in my kubernetes cluster, then check its status to see how long does it take for the pod to get down, and up again. I could not find any helpful example for the second part which is getting a specific pod status using…
setiabb
  • 529
  • 1
  • 5
  • 13
8
votes
3 answers

client-go: parse kubernetes json files to k8s structures

i would like to parse kubernetes manifest file (json/yaml) and be able to convert them to k8s structures (to later on manipulate them) I know there is the NewYAMLOrJSONDecoder().Decode() function…
Nicolas Zin
  • 121
  • 1
  • 1
  • 6
8
votes
4 answers

Validate Kubernetes Configuration files(YAML)

I would like to implement a functionality - that validates Kubernetes deployment files(deployments yaml or service yaml or rc yaml) using k8s JSON schema /Yaml Schema. Currently I need the setup kubectl and k8s cluster available in order to…
dkat
  • 213
  • 1
  • 5
  • 14
7
votes
2 answers

How do i create a namespace using kubernetes go-client from running container inside a cluster

I have a Kubernetes cluster and have a running container (X). From this container i want to create a new namespace, deploy a pod in this name space and spawn container(Y). I know kubernetes provides REST APIs. however, i am exploring goClient to do…
aks
  • 304
  • 3
  • 8
6
votes
1 answer

Patch kubernetes label with "/" character

I have the following code that is working fine. It adds the label example: yes in the kubernetes object: package main import ( "fmt" "encoding/json" "k8s.io/apimachinery/pkg/types" eksauth "github.com/chankh/eksutil/pkg/auth" …
pcampana
  • 2,413
  • 2
  • 21
  • 39
6
votes
2 answers

kubernetes client-go: convert labelselector to label string

In the kubernetes client-go API (or another library that uses it), is there a utility function to convert a k8s.io/apimachinery/pkg/apis/meta/v1/LabelSelector to a string to fill the field LabelSelector in…
bobbel
  • 461
  • 6
  • 18
6
votes
1 answer

How to drain a node using kubernetes python client?

I am trying to automate kubernetes worker nodes using the official kubernetes python-client. I am currently looking for a way to safely move al the running applications to other nodes . We can do so using "kubectl drain". I did not find a way to…
Swarup Donepudi
  • 984
  • 1
  • 11
  • 23
6
votes
1 answer

Kubernetes Ingress not accessible (localhost)

I am setting up a minimal Kubernetes cluster on localhost on a Linux machine (starting with hack/local-up-cluster from the checked out repo). In my deployment file I defined an ingress, which should make the services, which are deployed in the…
Skeffington
  • 1,281
  • 2
  • 10
  • 13
1
2 3
8 9