不确定我为什么要获取伪造的证书,即使该证书由 letencrypt 使用 certmanager
正确发行该设置在阿里云ECS控制台上运行,其中一个Kube-master和一个cube-minion组成一个kubernetes集群。
服务详细信息
root@kube-master:~# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h20m
my-nginx ClusterIP 10.101.150.247 <none> 80/TCP 77m
Pod详细信息
root@kube-master:~# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
my-nginx-6cc48cd8db-n6scm 1/1 Running 0 46s app=my-nginx,pod-template-hash=6cc48cd8db
部署了头盔证书管理器
root@kube-master:~# helm ls
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
cert-manager 1 Tue Mar 12 15:29:21 2019 DEPLOYED cert-manager-v0.5.2 v0.5.2 kube-system
kindred-garfish 1 Tue Mar 12 17:03:41 2019 DEPLOYED nginx-ingress-1.3.1 0.22.0 kube-system
正确颁发的证书
root@kube-master:~# kubectl describe certs
Name: tls-prod-cert
Namespace: default
Labels: <none>
Annotations: <none>
API Version: certmanager.k8s.io/v1alpha1
Kind: Certificate
Metadata:
Creation Timestamp: 2019-03-12T10:26:58Z
Generation: 2
Owner References:
API Version: extensions/v1beta1
Block Owner Deletion: true
Controller: true
Kind: Ingress
Name: nginx-ingress-prod
UID: 5ab11929-44b1-11e9-b431-00163e005d19
Resource Version: 17687
Self Link: /apis/certmanager.k8s.io/v1alpha1/namespaces/default/certificates/tls-prod-cert
UID: 5dad4740-44b1-11e9-b431-00163e005d19
Spec:
Acme:
Config:
Domains:
zariga.com
Http 01:
Ingress:
Ingress Class: nginx
Dns Names:
zariga.com
Issuer Ref:
Kind: ClusterIssuer
Name: letsencrypt-prod
Secret Name: tls-prod-cert
Status:
Acme:
Order:
URL: https://acme-v02.api.letsencrypt.org/acme/order/53135536/352104603
Conditions:
Last Transition Time: 2019-03-12T10:27:00Z
Message: Order validated
Reason: OrderValidated
Status: False
Type: ValidateFailed
Last Transition Time: <nil>
Message: Certificate issued successfully
Reason: CertIssued
Status: True
Type: Ready
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CreateOrder 27s cert-manager Created new ACME order, attempting validation...
Normal IssueCert 27s cert-manager Issuing certificate...
Normal CertObtained 25s cert-manager Obtained certificate from ACME server
Normal CertIssued 25s cert-manager Certificate issued successfully
入口详细信息
root@kube-master:~# kubectl describe ingress
Name: nginx-ingress-prod
Namespace: default
Address:
Default backend: my-nginx:80 (192.168.123.202:80)
TLS:
tls-prod-cert terminates zariga.com
Rules:
Host Path Backends
---- ---- --------
* * my-nginx:80 (192.168.123.202:80)
Annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: true
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CREATE 7m13s nginx-ingress-controller Ingress default/nginx-ingress-prod
Normal CreateCertificate 7m8s cert-manager Successfully created Certificate "tls-prod-cert"
Normal UPDATE 6m57s nginx-ingress-controller Ingress default/nginx-ingress-prod
加密Nginx生产定义
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress-prod
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
kubernetes.io/tls-acme: 'true'
labels:
app: 'my-nginx'
spec:
backend:
serviceName: my-nginx
servicePort: 80
tls:
- secretName: tls-prod-cert
hosts:
- zariga.com
答案 0 :(得分:5)
对于遇到类似问题的人可能会有所帮助。对于我来说,忘记了在rules
和tls
部分的Ingress yaml文件中指定主机名。
复制主机名后,它开始使用正确的证书进行响应。
示例:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-web-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
tls:
- hosts:
- my.host.com # <----
secretName: tls-secret
rules:
- host: my.host.com # <----
http:
paths:
- path: /
pathType: Prefix
backend:
serviceName: my-nginx
servicePort: 80
答案 1 :(得分:1)
如果您使用clusterissuer URL作为标记URL,有时可能会发生
检查是否要加密您正在使用的颁发者或clusterissuer中的URL,将其更改为生产url:https://acme-v02.api.letsencrypt.org/directory
我曾经遇到过同样的问题,然后将URL更改为已解决的生产URL。
还要检查您将正确的秘密指向入口的tls秘密
答案 2 :(得分:0)
重要的是,求解器的ClusterIssuer规范已更改。对于使用cer-manager>0.7.2
的人,此评论为我节省了很多时间:https://github.com/jetstack/cert-manager/issues/1650#issuecomment-518953464。专门介绍如何配置ClusterIssuer和证书。
答案 3 :(得分:0)
如果您确信一切设置正确但仍然无法正常工作,请尝试此操作。
编辑 nginx 控制器的部署。为什么?因为,如果它在部署的命名空间中找不到秘密,Nginx 控制器会部署它自己的证书(假证书)。不知道这一点(我是游戏新手)让我失去了几天的生命。
因此,要么更改为 Nginx Ingress 控制器所在的命名空间并获取部署名称,然后:
kubectl edit deployment nginx-ingress-ingress-nginx-controller -n nginx-ingress
或者如果该命名空间中只有一个部署,您可以这样做
kubectl edit deployment
并且您应该处于 nginx 控制器部署的编辑模式。查找部分:spec --> 容器:--> args:
spec:
containers:
- args:
- /nginx-ingress-controller
- --publish-service=$(POD_NAMESPACE)/nginx-ingress-ingress-nginx-controller
- --election-id=ingress-controller-leader
- --ingress-class=nginx
- --configmap=$(POD_NAMESPACE)/nginx-ingress-ingress-nginx-controller
- --validating-webhook=:8443
- --validating-webhook-certificate=/usr/local/certificates/cert
- --validating-webhook-key=/usr/local/certificates/key
- --default-ssl-certificate=app-namespace/letsencrypt-cert-prod
如果您的 nginx 控制器没有找到证书,您可以添加一个默认证书(如上所述),因此它将通过添加以下内容在命名空间中搜索秘密:
--default-ssl-certificate=your-cert-namespace/your-cert-secret
your-cert-namespace:您的证书密钥所在的命名空间 your-cert-secret:包含机密的证书名称
保存并关闭编辑器后,它应该会更新。然后检查您的证书管理器 pod 的日志:
kubectl logs cert-manager-xxxpodxx-abcdef -n cert-manager
确保一切正常。
如果您的所有资源都部署在同一个命名空间中,您可能不会遇到此问题。
答案 4 :(得分:0)
对我来说,问题是入口类名,因为我使用的是 microk8s,入口类名是 public
:
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
email: "your@email.tld"
privateKeySecretRef:
name: letsencrypt-prod
server: "https://acme-v02.api.letsencrypt.org/directory"
solvers:
- http01:
ingress:
class: public