Closed Noiri closed 3 years ago
cert-managerのchallenges内のセルフチェックに失敗してる
$ k get challenges/www-ictsc-test-tls-v62nm-696946275-2591328139 -o yaml
status:
presented: true
processing: true
reason: 'Waiting for HTTP-01 challenge propagation: failed to perform self check
GET request ''http://www.ictsc.test/.well-known/acme-challenge/UlUMqyBUR2S88rD20V5AVxx7Ud1R9V1k'':
Get "http://www.ictsc.test/.well-known/acme-challenge/UlUMqyBUR2S88rD20V5AVxx7Ud1R9V1k":
dial tcp 192.168.20.1:80: connect: connection timed out'
state: pending
pod内部からdnsでcurlの接続ができないせい
$ k exec ingress-nginx-controller-848bfcb64d-9sxdc -n ingress-nginx -it -- /bin/sh
/etc/nginx $ curl 192.168.20.1:80
^C
pod内からpingは通るしkeepaliveの設定が致命的に駄目 なんでまともに設定できないのに外部LB使うんですか?metalLBじゃ駄目なんです???
root@web-57c65d7444-78hkq:/# ping 192.168.20.1
PING 192.168.20.1 (192.168.20.1) 56(84) bytes of data.
64 bytes from 192.168.20.1: icmp_seq=1 ttl=63 time=2.02 ms
64 bytes from 192.168.20.1: icmp_seq=2 ttl=63 time=0.760 ms
64 bytes from 192.168.20.1: icmp_seq=3 ttl=63 time=0.652 ms
^C
--- 192.168.20.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 6ms
rtt min/avg/max/mdev = 0.652/1.142/2.015/0.619 ms
というかこれ一番まともな解決策がkeepaliveの設定変更なのになんで許可されてないの???????
keepaliveのログのこの部分だろ
Mar 06 22:38:21 lb Keepalived_healthcheckers[553]: Adding service [192.168.20.130]:tcp:30080 to VS [192.168.20.1]:tcp:80
Mar 06 22:38:21 lb Keepalived_healthcheckers[553]: IPVS cmd IP_VS_SO_SET_ADDDEST(1159) error: Destination already exists(17)
lbでiptableをいじって解決した
#!/bin/sh
iptables --table nat --append PREROUTING --in-interface eth1 --dst 192.168.20.1 --protocol tcp --dport 80 --jump DNAT --to 192.168.20.130:30080
iptables --table nat --append POSTROUTING --out-interface eth1 --source 192.168.20.128/25 --destination 192.168.20.130 --jump MASQUERADE
これでcert-managerのself checkが成功するようになり、証明書が発行された
user@host:~$ curl -L www.ictsc.test
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
原因はcert-managerのchallenges内のセルフチェックに失敗してることです
$ k get challenges/www-ictsc-test-tls-v62nm-696946275-2591328139 -o yaml
status:
presented: true
processing: true
reason: 'Waiting for HTTP-01 challenge propagation: failed to perform self check
GET request ''http://www.ictsc.test/.well-known/acme-challenge/UlUMqyBUR2S88rD20V5AVxx7Ud1R9V1k'':
Get "http://www.ictsc.test/.well-known/acme-challenge/UlUMqyBUR2S88rD20V5AVxx7Ud1R9V1k":
dial tcp 192.168.20.1:80: connect: connection timed out'
state: pending
k8sのpod内部からwww.ictsc.testのドメインのipアドレスにport80番での接続ができないため、cert-managerはself checkに失敗しています。
$ k exec ingress-nginx-controller-848bfcb64d-9sxdc -n ingress-nginx -it -- /bin/sh
/etc/nginx $ curl 192.168.20.1:80
^C
これはlbのkeepalivedの設定に不備があり、k8sクラスタ側のネットワークからport80番に接続があった場合にk8sのNodePortにproxyしない設定になっているためです。
これを解決するためにlbに以下のiptablesの設定しました。
#!/bin/sh
iptables --table nat --append PREROUTING --in-interface eth1 --dst 192.168.20.1 --protocol tcp --dport 80 --jump DNAT --to 192.168.20.130:30080
iptables --table nat --append POSTROUTING --out-interface eth1 --source 192.168.20.128/25 --destination 192.168.20.130 --jump MASQUERADE
これでcert-managerのself checkが成功するようになり、証明書が発行され、正しく接続できるようになりました。
user@host:~$ curl -L www.ictsc.test
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
(提出してない部分) また、以下のようなserviceファイルを用意し、systemdにより永続化しました
[Unit]
Description=iptable config to k8s
[Service]
Type=simple
ExecStart=/home/user/ipt.sh
Restart=on-failure
[Install]
WantedBy=default.target
概要 k8sクラスターにcert-managerをインストールしhttp01認証で証明書を発行するissuerを設定した。 その上でhostのnginxのpodを展開するDeploymentと、それを公開するService、Ingressを記述した/home/user/manifests/web.yamlを作成しapplyした。 しかし、なぜか証明書が発行されない。その理由と解決方法を報告してほしい。
前提条件 lbとhostのみSSHログインできる。 cert-managerで取得する証明書は自己署名証明書を使用している hostやcert-managerなど必要なものにはルートCA証明書をインストール済み hostのuserユーザーでkubectlコマンドが利用できる hostの/home/user/manifestsに今回applyしたmanifestが保存されている cert-manager.yaml ingress-controller.yaml root-ca.yamlは変更しないこと web.yamlの再展開(kubectl delete, kubectl applyなど)可 acme-serverには、追加でDNSサーバーが稼働しており以下のレコードが設定されている IN NS ictsc.test. IN A 192.168.20.125
ca IN A 192.168.20.125 www IN A 192.168.20.1 lbにはkeepalivedがインストールされている。 keepalivedの設定は変更しないこと 初期状態 hostでcurl -L www.ictsc.testを実行したとき以下のようなエラーになる curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above. hostでkubectl get certを実行したときwww-ictsc-test-tlsのREADYがFalseになっている 終了状態 hostでcurl -L www.ictsc.testを実行したときにnginxの初期ページが表示される 証明書が設定されている hostでkubectl get certを実行したときにwww-ictsc-test-tlsのREADYがTrueになっている