k8s 启动mysql
时间: 2023-10-14 08:59:02 浏览: 106
要在 Kubernetes 中启动 MySQL,你可以使用以下步骤:
1. 创建一个 MySQL 的 Deployment:
```
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:latest
env:
- name: MYSQL_ROOT_PASSWORD
value: your_password
```
请将 `your_password` 替换为你想要设置的 MySQL root 密码。
2. 创建一个 MySQL 的 Service:
```
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
```
3. 应用这些配置文件:
```
kubectl apply -f mysql-deployment.yaml
kubectl apply -f mysql-service.yaml
```
以上步骤将创建一个 MySQL 的 Deployment 和 Service,并将 MySQL 部署在 Kubernetes 集群中。你可以使用 Service 的 ClusterIP 地址来访问 MySQL。
阅读全文
相关推荐


















