前回までと今回の記事
前回発生した以下のエラー

今回はこれに挑む。
画面表示までの戦い
ネット記事を参考にしてみる
以下の記事を参考にmysqlのデータを削除する。

root@k8s-worker2:~# rm -rf /mnt/mysql_data/*
エラーが変わらず。
権限周りも問題なさそう。
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| my_database |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.02 sec)
mysql> select user, host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | % |
| testuser | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
こうなったら直にwordpressのpodからmysqlにアクセスしてやんよ!
こうなったらmysqlコマンドで「wordpressのpod」→「mysqlのpodのDB」とアクセスしてみる事に。
⚠️default-mysql-clientをインストールしようとして「E: Unable to locate package default-mysql-client」が出たら、apt updateしてください。
root@test-wordpress-5685cc486b-6mtfg:/var/www/html# apt install default-mysql-client
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package default-mysql-client
root@test-wordpress-5685cc486b-6mtfg:/var/www/html# apt update
root@test-wordpress-5685cc486b-6mtfg:/var/www/html# apt install default-mysql-client
wordpressのpodの中から、mysqlにアクセス
root@test-wordpress-5685cc486b-6mtfg:/var/www/html# mysql -h test-wp-mysql -u testuser -ptestpassword my_database
ERROR 2002 (HY000): Can't connect to server on 'test-wp-mysql' (115)
アクセスできない。
telnetでそもそも「wordpressのpod」→「mysqlのpod」がアクセスできるかを確認。
# telnet test-wp-mysql 3306
Trying 10.102.64.173...
Connected to test-wp-mysql.
Escape character is '^]'.
I
x:nDcaching_sha2_password2#08S01Got timeout reading communication packetsConnection closed by foreign host.
アクセスはできることは確認できました。
rootで「wordpressのpod」→「mysqlのpodの中のDB」にアクセスしてみます。
root@test-wordpress-5685cc486b-6mtfg:/var/www/html# mysql -h test-wp-mysql -u testuser -p
Enter password:
ERROR 2002 (HY000): Can't connect to server on 'test-wp-mysql' (115)
root@test-wordpress-5685cc486b-6mtfg:/var/www/html# mysql -h test-wp-mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.4.3 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
入れました。
今度はmysqlのpodの中でDBからはtestuserで入れるか試してみる。
→入れたのでパスワードが間違っているってことは無さそう。
bash-5.1# mysql -u testuser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.4.3 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
権限な気がする🤔🤔🤔
いや、入れた。DB指定していないと入れるのか?
# mysql -h test-wp-mysql -u testuser -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.4.3 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
やっぱりDBを指定すると入れない
root@test-wordpress-5685cc486b-6mtfg:/var/www/html# mysql -h test-wp-mysql -u testuser -p my_database
Enter password:
ERROR 2002 (HY000): Can't connect to server on 'test-wp-mysql' (115)
DB周りの権限を確認してみよう
👇
あれ?エスケープみたいなバックスラッシュが入っている。。。
これかしら??
mysql> SHOW GRANTS FOR 'testuser'@'%';
+------------------------------------------------------------+
| Grants for testuser@% |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO `testuser`@`%` |
| GRANT ALL PRIVILEGES ON `my\_database`.* TO `testuser`@`%` |
+------------------------------------------------------------+
設定し直す。
mysql> GRANT ALL PRIVILEGES ON my_database.* TO 'testuser'@'%';
Query OK, 0 rows affected (0.02 sec)
mysql> SHOW GRANTS FOR 'testuser'@'%';
+------------------------------------------------------------+
| Grants for testuser@% |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO `testuser`@`%` |
| GRANT ALL PRIVILEGES ON `my\_database`.* TO `testuser`@`%` |
| GRANT ALL PRIVILEGES ON `my_database`.* TO `testuser`@`%` |
+------------------------------------------------------------+
wordpressのpodからmysqlのpod内のmy_databaseにアクセスできた。
root@test-wordpress-767cdf5689-lltgb:/var/www/html# mysql -h test-wp-mysql -u testuser -p my_database
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.4.3 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [my_database]>
アンダーバー入れるのが怖いのでDB名を「my_database」→「wordpress」に変更
- name: WORDPRESS_DB_NAME
value: wordpress
アクセスの確認
root@test-wordpress-c945d569-zmxnr:/var/www/html# mysql -h test-wp-mysql -u testuser -p wordpress
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.3 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [wordpress]>
サイドcurlにてアクセス確認→404エラー
$ curl 192.168.3.100/testwordpress/
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
もぉ~いや。(ブパパブパパ)(cf. メープル超合金)
wordpress側のlogを確認するとリダイレクトされていることが分かった(302はリダイレクトされているということ)
"GET / HTTP/1.1" 302 348 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
curlだと分からないが、
ブラウザで192.168.3.100/testwordpress/にアクセスすると、
「192.168.3.100/testwordpress/」→「192.168.3.100/wp-admin/install.php」
にリダイレクトされている。
いや、
「192.168.3.100/testwordpress/wp-admin/install.php」
にならんのかいっ!
ingressのpathを以下のように変更。
- path: / # ★★
pathType: Prefix
backend:
service:
name: test-wordpress-service
port:
number: 80
これで、やっとたどり着いた…。

まとめ
やっとwordpressの画面を表示できました。
k8sが上手くいかないというより、wordpressとmysqlの設定周りに翻弄されたように思えます。