我们有一个按预期工作的kubebuilder控制器,现在我们需要创建一个webhooks,
我遵循教程https://book.kubebuilder.io/reference/markers/webhook.html,现在我想在本地运行和调试它,但是不知道如何处理证书,是否有一种简单的方法来创建它,任何示例都将非常有用。
顺便说一下,我已经安装了证书经理并应用了下面的示例yaml,但不确定下一步要做什么.
我需要最简单的解决方案,我能够在本地运行和调试webhook的本地,就像我已经使用控制器所做的那样(在使用webhooks之前),
https://book.kubebuilder.io/cronjob-tutorial/running.html
证书经理
我在集群中创建了以下内容
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本地的最简单的方法
发布于 2022-12-02 05:04:12
让我从一开始就告诉你这个过程。
kubebuilder create webhook --group batch --version v1 --kind CronJob --defaulting --programmatic-validation中所说的那样。这将创建用于实现默认逻辑和验证逻辑的webhooks。kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.10.1/cert-manager.yaml。config/default/kustomization.yaml文件,取消注释所有在评论中包含WEBHOOK或CERTMANAGER的内容。对config/crd/kustomization.yaml文件也做同样的操作。make docker-build IMG=<some-registry>/<project-name>:tag在本地构建图像。现在,您不需要将映像docker-push到远程存储库。如果使用的是种类群集,则可以直接将本地映像加载到指定种类的群集:kind load docker-image <your-image-name>:tag --name <your-kind-cluster-name>。make deploy IMG=<some-registry>/<project-name>:tag将其部署到集群中。还可以使用make run命令在本地运行集群。但是,如果您启用了webook,这就有点棘手了。我建议您使用这样的方式运行集群。在这里,您不需要担心注入证书。证书经理会帮你的。您可以查看/config/certmanager文件夹来了解它是如何工作的。
发布于 2022-12-03 16:43:34
我假设您可以在这里使用openssl命令:
首先,为证书生成一个私钥:
openssl genrsa -out webhook.key 2048然后,使用私钥生成证书签名请求(CSR):
openssl req -new -key webhook.key -out webhook.csr接下来,使用私钥和CSR创建一个自签名证书:
openssl x509 -req -in webhook.csr -signkey webhook.key -out webhook.crt最后,您可以使用kubebuilder配置中的webhook.crt和webhook.key文件在本地运行和调试web钩子。
https://stackoverflow.com/questions/74581276
复制相似问题