自作Helm Chartのwordpressをブラウザで確認する①(案の定k8sが上手くいかない #8)

スポンサーリンク
個人開発
スポンサーリンク

前回はwordpressとmysqlの環境までを払い出したので、

今回はHelmで払い出したwordpress環境にブラウザからアクセスすることを試みます。

参考にしたのは以下のサイトです。

実装

実装していきます。

metallbで外部IPを設定する。

以下の手順を行っていく。

以下のコマンドを実行。

$ cat <<EOF | kubectl apply -f -
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: ingress-address-pool
  namespace: metallb-system
spec:
  addresses:
  - 192.168.3.100-192.168.3.200
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: ingress-l2-advertisement
  namespace: metallb-system
spec:
  ipAddressPools:
  - ingress-address-pool
EOF

ingress-nginx-controllerがNodeportだったのでLoadBalancerに切り替え

$ kubectl patch service ingress-nginx-controller -n ingress-nginx -p '{"spec": {"type": "LoadBalancer"}}'
service/ingress-nginx-controller patched (no change)

External IPが設定されているか確認。(ここでは仮に192.168.3.100と書いてますが、実際はXXとYYYのところは任意の数字になります)

$ kubectl get service ingress-nginx-controller -n ingress-nginx
NAME                       TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)                      AGE
ingress-nginx-controller   LoadBalancer   10.96.150.131   192.168.3.100   80:32639/TCP,443:30748/TCP   83d

PHP Fatal error: __autoload() is no longer supported, use spl_autoload_register() instead in /var/www/html/wp-includes/compat.php on line 502 が消えない

wordpress側のログに以下エラー

$ kubectl logs test-wordpress-5c496bbdb8-cnptv -n wp
[Sun Nov 17 08:18:47.581787 2024] [mpm_prefork:notice] [pid 1:tid 1] AH00163: Apache/2.4.62 (Debian) PHP/8.1.30 configured -- resuming normal operations
[Sun Nov 17 08:18:47.581938 2024] [core:notice] [pid 1:tid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[17-Nov-2024 13:27:06 UTC] PHP Fatal error:  __autoload() is no longer supported, use spl_autoload_register() instead in /var/www/html/wp-includes/compat.php on line 502
127.0.0.1 - - [17/Nov/2024:13:27:06 +0000] "GET / HTTP/1.1" 500 211 "-" "curl/7.88.1"

「PHP Fatal error: __autoload() is no longer supported, use spl_autoload_register() instead in /var/www/html/wp-includes/compat.php on line 502」

というエラーは調べるとPHPのバージョンが古いと発生するらしい。

ためしに、wordpressのイメージのバージョンを上げてもまだエラーは発生し続ける。

PHPのバージョンを確認

$ kubectl exec -it test-wordpress-6f9bc84bf8-r68wr -n ingress-nginx -- php -v
PHP 8.0.28 (cli) (built: May  3 2023 05:34:55) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.28, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.28, Copyright (c), by Zend Technologies

バージョンは適切に見える。

これは、ボリュームが永続化されているからだった。

ボリューム先のフォルダを削除したら解消した。

root@k8s-worker2:~# ls /mnt/data
index.php        wp-admin              wp-config.php  wp-links-opml.php  wp-settings.php
license.txt      wp-blog-header.php    wp-content     wp-load.php        wp-signup.php
readme.html      wp-comments-post.php  wp-cron.php    wp-login.php       wp-trackback.php
wp-activate.php  wp-config-sample.php  wp-includes    wp-mail.php        xmlrpc.php

ファイル群を削除

root@k8s-worker2:~# rm -rf /mnt/data/*

再度、helm installで再構築して、再アクセス。

なんかつながった様。けど、errorっぽい。

$ curl 192.168.3.100/testwordpress
<!DOCTYPE html>
<html dir='ltr'>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
                        <title>Database Error</title>
        <style type="text/css">
                html {
                        background: #f1f1f1;
                }
                body {
                        background: #fff;
                        border: 1px solid #ccd0d4;
                        color: #444;
                        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
                        margin: 2em auto;
                        padding: 1em 2em;
                        max-width: 700px;
                        -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
                        box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
                }
                h1 {
                        border-bottom: 1px solid #dadada;
                        clear: both;
                        color: #666;
                        font-size: 24px;
                        margin: 30px 0 0 0;
                        padding: 0;
                        padding-bottom: 7px;
                }
                #error-page {
                        margin-top: 50px;
                }
                #error-page p,
                #error-page .wp-die-message {
                        font-size: 14px;
                        line-height: 1.5;
                        margin: 25px 0 20px;
                }
                #error-page code {
                        font-family: Consolas, Monaco, monospace;
                }
                ul li {
                        margin-bottom: 10px;
                        font-size: 14px ;
                }
                a {
                        color: #2271b1;
                }
                a:hover,
                a:active {
                        color: #135e96;
                }
                a:focus {
                        color: #043959;
                        box-shadow: 0 0 0 2px #2271b1;
                        outline: 2px solid transparent;
                }
                .button {
                        background: #f3f5f6;
                        border: 1px solid #016087;
                        color: #016087;
                        display: inline-block;
                        text-decoration: none;
                        font-size: 13px;
                        line-height: 2;
                        height: 28px;
                        margin: 0;
                        padding: 0 10px 1px;
                        cursor: pointer;
                        -webkit-border-radius: 3px;
                        -webkit-appearance: none;
                        border-radius: 3px;
                        white-space: nowrap;
                        -webkit-box-sizing: border-box;
                        -moz-box-sizing:    border-box;
                        box-sizing:         border-box;

                        vertical-align: top;
                }

                .button.button-large {
                        line-height: 2.30769231;
                        min-height: 32px;
                        padding: 0 12px;
                }

                .button:hover,
                .button:focus {
                        background: #f1f1f1;
                }

                .button:focus {
                        background: #f3f5f6;
                        border-color: #007cba;
                        -webkit-box-shadow: 0 0 0 1px #007cba;
                        box-shadow: 0 0 0 1px #007cba;
                        color: #016087;
                        outline: 2px solid transparent;
                        outline-offset: 0;
                }

                .button:active {
                        background: #f3f5f6;
                        border-color: #7e8993;
                        -webkit-box-shadow: none;
                        box-shadow: none;
                }

                        </style>
</head>
<body id="error-page">
        <div class="wp-die-message"><h1>Error establishing a database connection</h1></div></body>
</html>

ブラウザからアクセスしてみてみると。

確かにアクセスはできているっぽいが、エラーが出ている。

嗚呼、もう疲れた。

タイトルとURLをコピーしました