【问题标题】:kubernetes ingress not accepting the self signed sslkubernetes 入口不接受自签名 ssl
【发布时间】:2022-10-23 18:22:14
【问题描述】:

我的 kubernetes 入口不接受自签名证书,而是在 Firefox 上打开 URL 时Kubernetes 入口控制器假证书被添加。

在 Kali Linus 中使用 minikube 在 pc 上本地完成所有事情。卡利 linus 正在通过 VMWare 软件在虚拟机中运行。 我指的是—— https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-multi-ssl

Ingress Yaml 文件。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: first-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
  - secretName: myssl
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: first-service
            port:
              number: 8080

“192.168.49.2”是入口 IP 地址。所以https://192.68.42.2 在浏览器上打开我的应用程序。

证书是使用 Openssl 使用以下命令生成的:

openssl genrsa -out s.key 2048
openssl req -new -key s.key -out s.csr -subj "/CN=example.com"
openssl x509 -req -days 365 -in s.csr -signkey s.key -out s.crt

证书被添加到 k8s secret 中。

kubectl create secret tls myssl --cert s.crt --key s.key

curl -kv https://192.168.49.2 命令输出为:

* Trying 192.168.49.2:443...
* Connected to 192.168.49.2 (192.168.49.2) port 443 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS header, Finished (20):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.2 (OUT), TLS header, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN: server accepted h2
* Server certificate:
*  subject: O=Acme Co; CN=Kubernetes Ingress Controller Fake Certificate
*  start date: Oct 22 09:57:19 2022 GMT
*  expire date: Oct 22 09:57:19 2023 GMT
*  issuer: O=Acme Co; CN=Kubernetes Ingress Controller Fake Certificate
*  SSL certificate verify result: self-signed certificate (18), continuing anyway.
* Using HTTP2, server supports multiplexing
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* h2h3 [:method: GET]
* h2h3 [:path: /]
* h2h3 [:scheme: https]
* h2h3 [:authority: 192.168.49.2]
* h2h3 [user-agent: curl/7.85.0]
* h2h3 [accept: */*]
* Using Stream ID: 1 (easy handle 0x561c242ff950)
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
> GET / HTTP/2
> Host: 192.168.49.2
> user-agent: curl/7.85.0
> accept: */*
> 
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
< HTTP/2 200 
< date: Sat, 22 Oct 2022 10:05:50 GMT
< content-type: text/html; charset=utf-8
 ..... html of the page
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Connection #0 to host 192.168.49.2 left intact

describe Ingress 的输出是:

kubectl describe ingress first-ingress
Name:             first-ingress
Labels:           <none>
Namespace:        default
Address:          192.168.49.2
Ingress Class:    <none>
Default backend:  <default>
TLS:
  myssl terminates 
Rules:
  Host        Path  Backends
  ----        ----  --------
  *           
              /   first-service:8080 (172.17.0.2:80)
Annotations:  nginx.ingress.kubernetes.io/force-ssl-redirect: true
              nginx.ingress.kubernetes.io/rewrite-target: /
              nginx.ingress.kubernetes.io/ssl-redirect: true
Events:
  Type    Reason  Age                   From                      Message
  ----    ------  ----                  ----                      -------
  Normal  Sync    87m (x5 over 140m)    nginx-ingress-controller  Scheduled for sync
  Normal  Sync    3m51s (x10 over 37m)  nginx-ingress-controller  Scheduled for sync

描述秘密的输出是

kubectl describe secret myssl
Name:         myssl
Namespace:    default
Labels:       <none>
Annotations:  <none>

Type:  kubernetes.io/tls

Data
====
tls.crt:  1180 bytes
tls.key:  1704 bytes

请帮忙。

2天后更新:

我调试并发现我已经使用以下命令安装了 nginx 入口:

minikube addons enable ingress

它将入口安装在 ingress-nginx 命名空间中,而我的秘密在 default 命名空间中。这可能是问题,如果是,解决方案是什么?

【问题讨论】:

标签: kubernetes ssl kubernetes-ingress


【解决方案1】:

您的入口清单中有一个错误,这里:

rules:
- host: example.com
- http:
    paths:

您创建了两个规则,第一个匹配 host: example.com 但没有定义路径或后端;第二个匹配路径/,但没有设置host。你要:

rules:
- host: example.com
  http:
    paths:

【讨论】:

  • 我尝试了您的解决方案,但它不起作用。
  • 我还想补充一点,我在本地执行此操作,因此在我的情况下不会有主机。那么如何做到这一点,因为在我的情况下,入口调用是使用它的 IP 地址而不是主机名完成的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-16
  • 1970-01-01
  • 2011-08-25
  • 2019-11-04
  • 2020-08-14
  • 2013-04-01
  • 2015-11-02
相关资源
最近更新 更多