首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >kubebuilder本地调试web钩子

kubebuilder本地调试web钩子
EN

Stack Overflow用户
提问于 2022-11-26 10:12:09
回答 2查看 157关注 0票数 3

我们有一个按预期工作的kubebuilder控制器,现在我们需要创建一个webhooks,

我遵循教程https://book.kubebuilder.io/reference/markers/webhook.html,现在我想在本地运行和调试它,但是不知道如何处理证书,是否有一种简单的方法来创建它,任何示例都将非常有用。

顺便说一下,我已经安装了证书经理并应用了下面的示例yaml,但不确定下一步要做什么.

我需要最简单的解决方案,我能够在本地运行和调试webhook本地,就像我已经使用控制器所做的那样(在使用webhooks之前),

https://book.kubebuilder.io/cronjob-tutorial/running.html

证书经理

我在集群中创建了以下内容

代码语言:javascript
复制
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: example-com
  namespace: test
spec:
  # Secret names are always required.
  secretName: example-com-tls

  # secretTemplate is optional. If set, these annotations and labels will be
  # copied to the Secret named example-com-tls. These labels and annotations will
  # be re-reconciled if the Certificate's secretTemplate changes. secretTemplate
  # is also enforced, so relevant label and annotation changes on the Secret by a
  # third party will be overwriten by cert-manager to match the secretTemplate.
  secretTemplate:
    annotations:
      my-secret-annotation-1: "foo"
      my-secret-annotation-2: "bar"
    labels:
      my-secret-label: foo

  duration: 2160h # 90d
  renewBefore: 360h # 15d
  subject:
    organizations:
      - jetstack
  # The use of the common name field has been deprecated since 2000 and is
  # discouraged from being used.
  commonName: example.com
  isCA: false
  privateKey:
    algorithm: RSA
    encoding: PKCS1
    size: 2048
  usages:
    - server auth
    - client auth
  # At least one of a DNS Name, URI, or IP address is required.
  dnsNames:
    - example.com
    - www.example.com
  uris:
    - spiffe://cluster.local/ns/sandbox/sa/example
  ipAddresses:
    - 192.168.0.5
  # Issuer references are always required.
  issuerRef:
    name: ca-issuer
    # We can reference ClusterIssuers by changing the kind here.
    # The default value is Issuer (i.e. a locally namespaced Issuer)
    kind: Issuer
    # This is optional since cert-manager will default to this value however
    # if you are using an external issuer, change this to that issuer group.
    group: cert-manager.io

仍然不确定如何将其与kubebuilder同步以在本地工作。

与在调试模式下运行操作符时一样,我得到了以下错误:

setup problem running manager {"error": "open /var/folders/vh/_418c55133sgjrwr7n0d7bl40000gn/T/k8s-webhook-server/serving-certs/tls.crt: no such file or directory"}

我需要的是运行webhooks本地的最简单的方法

EN

回答 2

Stack Overflow用户

发布于 2022-12-02 05:04:12

让我从一开始就告诉你这个过程。

  1. 创建webhook,就像cronJob教程- kubebuilder create webhook --group batch --version v1 --kind CronJob --defaulting --programmatic-validation中所说的那样。这将创建用于实现默认逻辑和验证逻辑的webhooks。
  2. 按照指示实现逻辑- 实现默认/验证webhooks
  3. 安装证书管理器。我发现安装最简单的方法是通过这个逗号- kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.10.1/cert-manager.yaml
  4. 编辑config/default/kustomization.yaml文件,取消注释所有在评论中包含WEBHOOK或CERTMANAGER的内容。对config/crd/kustomization.yaml文件也做同样的操作。
  5. 使用- make docker-build IMG=<some-registry>/<project-name>:tag在本地构建图像。现在,您不需要将映像docker-push到远程存储库。如果使用的是种类群集,则可以直接将本地映像加载到指定种类的群集:kind load docker-image <your-image-name>:tag --name <your-kind-cluster-name>
  6. 现在您可以通过- make deploy IMG=<some-registry>/<project-name>:tag将其部署到集群中。

还可以使用make run命令在本地运行集群。但是,如果您启用了webook,这就有点棘手了。我建议您使用这样的方式运行集群。在这里,您不需要担心注入证书。证书经理会帮你的。您可以查看/config/certmanager文件夹来了解它是如何工作的。

票数 0
EN

Stack Overflow用户

发布于 2022-12-03 16:43:34

我假设您可以在这里使用openssl命令:

首先,为证书生成一个私钥:

代码语言:javascript
复制
openssl genrsa -out webhook.key 2048

然后,使用私钥生成证书签名请求(CSR):

代码语言:javascript
复制
openssl req -new -key webhook.key -out webhook.csr

接下来,使用私钥和CSR创建一个自签名证书:

代码语言:javascript
复制
openssl x509 -req -in webhook.csr -signkey webhook.key -out webhook.crt

最后,您可以使用kubebuilder配置中的webhook.crtwebhook.key文件在本地运行和调试web钩子。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74581276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档