我是 Kubernetes 新手,尝试使用 Kubernetes pod 容器部署 WordPress 和 MySQL,但在运行 Kubernetes 时抛出错误“建立数据库连接时出错”
以下是我的 pod 和服务定义文件
秘密.yaml
apiVersion: v1
kind: Secret
metadata:
name: mysql-pass
type: Opaque
data:
username: XXXXX
password: XXXXX
mysql-pod-defination-file.yaml
apiVersion: v1
kind: Pod
metadata:
name: mysql-app
labels:
name: mysql-app-label
spec:
containers:
- image: mysql:5.6
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
name: mysql-image
ports:
- containerPort: 3306
wordpress-pod-defination-file.yaml
apiVersion: v1
kind: Pod
metadata:
name: wordpress-app
labels:
name: wordpress-app-label
spec:
containers:
- image: wordpress:apache
name: wordpress-image
env:
- name: WORDPRESS_DB_HOST
value: db
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 80
mysql-服务-defiantion-file.yaml
apiVersion: v1
kind: Service
metadata:
name: db
labels:
name: db-service
app: demo-wordpress-app
spec:
ports:
- port: 3306
selector:
name: mysql-app-label
wordpress 服务定义文件 yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress-service
labels:
name: wordpress-service
app: demo-wordpress-app
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
selector:
name: wordpress-app-label
我能够从 minikube Pod 容器内成功连接到 mysql 数据库
我的定义文件有什么问题吗?