天道酬勤,学无止境

client-go

Issue using in-cluster kubernetes configuration with client-go library on google cloud build

I'm having a bit of a challenge try to build my app which is using the golang client-go library. What the app does is provide and api which then deploys a pod to a kubernetes cluster. Now the app is able to deploy a pod successfully if I use an out of cluster kubernetes(i.e minikube) config which is found in $HOME/.kube/config. See code below that determines which config to use depending on the config path; package kubernetesinterface import ( "log" "os" core "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth"

2021-08-12 14:18:15    分类:问答    kubernetes   google-cloud-build   client-go

How to filter finished jobs in kubernetes

I'm trying to filter jobs that are complete using golang kubernetes client-go lib by their status. I've checked other answers explaining how to get the jobs using kubectl, like this: kubectl get job -o=jsonpath='{.items[?(@.status.succeeded==1)].metadata.name}' But I don't know how to "turn" that jsonpath output into a filter or list options If I were searching for pods by their status phase and a label I would do something like this: listOptions := metav1.ListOptions{ LabelSelector: "app.kubernetes.io/name=my-custom-job", FieldSelector: "status.phase=Running", } result, err := clientset

2021-06-28 09:17:25    分类:问答    go   kubernetes   kubectl   client-go

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 parse the files using this code scheme.Codecs.UniversalDeserializer().Decode, and I get back an array of runtime.Object. I know that all the Kubernetes resources conform to the runtime.Object interface, but I can't find a way to submit the generic interface to the API. Most methods I've seen use the methods on the concrete types like Deployment, Pod

2021-06-01 18:26:44    分类:问答    kubernetes   kubernetes-apiserver   client-go

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 kubectl apply of this manifest in Go code, using client-go. I understand that I need to do some (un)marshalling of the YAML bytes into the correct API types defined in package: https://github.com/kubernetes/api I have successfully Createed single API types to my cluster, but how do I do this for a manifest that contains a list of types that are not the

2021-05-24 16:18:02    分类:问答    go   kubernetes   kubernetes-apiserver   client-go

kubernetes源码剖析之client-go(二) Informer机制

kubernetes源码剖析之client-go(一) Informer机制   Kubernetes通过informer机制,实现在不依赖任何中间件的情况下保证消息的实时性、可靠性、顺序性。其他Kubernetes组件通过client-go的informer机制与Api Server进行通信。Informer的核心组件包括: Reflector 用于监控(Watch)指定Kubernetes资源 DeltaFIFO  Delta的先进先出队列,Reflector为生产者,Controller为消费者 Indexer 自带索引功能的本地存储,用于存储资源对象 Infermers 运行原理 代码示例 package main import ( "log" "time" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/clientcmd" ) func main() { config, err := clientcmd.BuildConfigFromFlags("", "D:\\coding\\config") if err

2021-03-27 00:19:53    分类:博客    kubernets   client-go   go

kubernetes源码剖析之client-go(一)

kubernetes源码剖析之client-go(一)   刚入k8s和go的坑,碰巧看到社区的源码研习活动,赶紧加入开始学习阅读clinet-go(client-go源码地址)  Kubernetes中使用client-go作为Go语言的官方编程式交互客户端库,提供对api server服务的交互访问。对于k8s的二次开发,熟练掌握client-go是十分必要的。 client-go源码结构 cubix@DESKTOP-H2868FG MINGW64 /d/coding/go/src/k8s.io/client-go (14) $ tree -L 1 . |-- CHANGELOG.md |-- CONTRIBUTING.md |-- Godeps |-- INSTALL.md |-- LICENSE |-- OWNERS |-- README.md |-- SECURITY_CONTACTS |-- code-of-conduct.md |-- discovery # 提供DiscoveryClient发现客户端 |-- dynamic # 提供DynamicClient动态客户端 |-- examples |-- go.mod |-- go.sum |-- informers # 每种kubernetes资源的Informer实现 |-- kubernetes #

2021-03-27 00:18:37    分类:博客    kubernetes   client-go   go