Answer the question
In order to leave comments, you need to log in
How to connect to Mysql in Minikube/Kubernetes?
Good afternoon!
I did test tasks on kubernetes/minikube:
https://github.com/ivekov/minikubeNginxPhpMysql
I have the minikube --driver=none;
following problem running:
Message: SQLSTATE[HY000] [1045] Access denied for user 'crud'@'172.17.0.6' (using password: YES)
mysql> SELECT db, host, user FROM mysql.db WHERE db='mainDb';
+--------+------------+------+
| db | host | user |
+--------+------------+------+
| mainDb | % | root |
| mainDb | 172.17.0.6 | crud |
+--------+------------+------+
2 rows in set (0.00 sec)
$app->get('/test/', function() {
$link = mysqli_connect("mysql", "root", "YWRtaW4=", "mainDb");
if (!$link) {
echo "Ошибка: Невозможно установить соединение с MySQL." . PHP_EOL;
echo "Код ошибки errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Текст ошибки error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Соединение с MySQL установлено!" . PHP_EOL;
echo "Информация о сервере: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
});
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'172.17.0.6' (using password: YES) in /var/www/html/public/index.php on line 44
Error: Unable establish a connection to MySQL. Error code errno: 1045 Error text error: Access denied for user 'root'@'172.17.0.6' (using password: YES)
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql-ss
spec:
selector:
matchLabels:
app: my-php-app
serviceName: mysql-service
replicas: 1
template:
metadata:
labels:
app: my-php-app
spec:
containers:
- name: mysql
image: mariadb
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-vm
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
volumes:
- name: mysql-vm
persistentVolumeClaim:
claimName: mysql-pvc
- name: config-volume
configMap:
name: mysql-conf
apiVersion: v1
kind: Secret
metadata:
creationTimestamp: null
name: mysql-pass
type: Opaque
data:
password: YWRtaW4=
Answer the question
In order to leave comments, you need to log in
And the user was added already through the local machine
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question