标签: operator-sdk

Kubernetes Operator(Operator SDK、Kubebuilder 与 Kubernetes 客户端库)

如果这个问题已经得到解答,我很抱歉,但在尝试了多种不同的谷歌搜索方式后,我未能得到明确的解释,所以我试图在这里寻求澄清。

我熟悉 Kubernetes 上下文中的操作员/控制器模式,并且正在尝试构建一个自定义 NodeJS 控制器,该控制器使用Kubernetes.io中的 NodeJS Kubernetes 客户端库之一来处理我自己的自定义资源 (CRD) 。

在网上研究时,我遇到了 OperatorSDK 和 Kubebuilder,它们似乎是可以引导操作员/控制器的工具,提供与 K8s Api 服务器接口的许多功能,就像 Kubernetes 客户端库一样。

OperatorSDK 和 Kubebuilder 似乎不仅仅是库所以这是我的问题

  1. OperatorSDK、KubebuilderKubernetes.ioKubernetes 客户端库之间有什么区别
  2. Kubernetes 客户端库是否实现了 OperatorSDK 和 Kubebuilder 之类的东西?
  3. 我是否需要使用 OperatorSDK 或 Kubebuilder 来实现我自己的控制器,因为据我所知,Kubernetes 客户端库似乎就足够了。

kubernetes kubernetes-operator operator-sdk

9
推荐指数
1
解决办法
1778
查看次数

List custom resources from caching client with custom fieldSelector

I'm using the Operator SDK to build a custom Kubernetes operator. I have created a custom resource definition and a controller using the respective Operator SDK commands:

operator-sdk add api --api-version example.com/v1alpha1 --kind=Example
operator-sdk add controller --api-version example.com/v1alpha1 --kind=Example
Run Code Online (Sandbox Code Playgroud)

在主协调循环中(对于上面的示例,自动生成的ReconcileExample.Reconcile方法),我有一些自定义业务逻辑,需要我在 Kubernetes API 中查询具有特定字段值的同类其他对象。我突然想到,我也许可以使用默认的 API 客户端(由控制器提供)和自定义字段选择器:

func (r *ReconcileExample) Reconcile(request reconcile.Request) (reconcile.Result, error) {
    ctx := context.TODO()
    listOptions := client.ListOptions{
        FieldSelector: fields.SelectorFromSet(fields.Set{"spec.someField": "someValue"}),
        Namespace:     request.Namespace,
    }
    otherExamples := v1alpha1.ExampleList{}

    if err := r.client.List(ctx, &listOptions, &otherExamples); err != nil { …
Run Code Online (Sandbox Code Playgroud)

go kubernetes operator-sdk

8
推荐指数
1
解决办法
3727
查看次数

两个K8S控制器同时修改同一个资源可以吗?

我有一些 CRD,每个 CRD 都应该Container.Spec在整个集群中进行 edit 。如 ENV、标签等...

如果资源由多个控制器管理,可以吗?

这种方法可能存在哪些缺陷?

kubernetes kubernetes-custom-resources kubernetes-operator operator-sdk

5
推荐指数
1
解决办法
1208
查看次数

无法更新自定义资源的状态字段

我正在使用 Operator-sdk 构建一个基于 GO 的操作员来管理名为“Module拥有部署”的自定义资源。我的_types.go看起来像这样:

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:subresource:scale:specpath=.spec.workerSettings.replicas,statuspath=.status.replicas,selectorpath=.status.selector
//+kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".spec.workerSettings.replicas",description="The number of pods for this Module"
//+kubebuilder:printcolumn:name="Ready",type="integer",JSONPath=".status.readyReplicas",description="The number of ready pods for this Module"
//+kubebuilder:resource:shortName=mod;mods

// Module is the Schema for the Module API
type Module struct {
    metav1.TypeMeta   `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty"`

    Spec   ModuleSpec   `json:"spec,omitempty"`
    Status ModuleStatus `json:"status,omitempty"`
}

// ModuleStatus defines the observed state of Module
type ModuleStatus struct {
    Replicas      int32              `json:"replicas"`
    ReadyReplicas int32              `json:"readyReplicas"`
    Selector      string             `json:"selector"`
    Conditions    []metav1.Condition `json:"conditions"`
}
Run Code Online (Sandbox Code Playgroud)

在协调中,我尝试设置ReadyReplicasCR …

go kubernetes kubernetes-custom-resources operator-sdk

5
推荐指数
0
解决办法
1146
查看次数

Kubernetes Ansible Operators - 修补现有的 Kubernetes 资源

使用 ansible:是否可以使用 json 或 yaml 片段修补资源?我基本上希望能够完成与 , 相同的事情kubectl patch <Resource> <Name> --type='merge' -p='{"spec":{ "test":"hello }}'来附加/修改资源规范。

https://docs.ansible.com/ansible/latest/modules/k8s_module.html 是否可以使用 k8s ansible 模块来做到这一点?它说如果一个资源已经存在并且“状态:存在”被设置为它将修补它,但是据我所知它并没有修补

谢谢

ansible kubernetes kubernetes-custom-resources operator-sdk

4
推荐指数
1
解决办法
1875
查看次数

如何使用自定义资源的分数格式(即 X/Y)显示 kubectl 列

在 Kubernetes 中,是否可以使用 CRD 的“additionalPrinterColumns”字段以分数格式(即 X/Y)显示列?

更准确地说,我想kubectl使用与下面的 READY 字段相同的格式显示 CR 字段的描述:

kubectl get statefulsets.apps <my-statefulset>
NAME              READY   AGE
<my-statefulset>  2/2     18m
Run Code Online (Sandbox Code Playgroud)

您能否提供“additionalPrinterColumns”部分的内容?

kubernetes kubernetes-custom-resources kubebuilder operator-sdk

3
推荐指数
1
解决办法
1671
查看次数