Kubernetes 示例 - 部署 mysql 服务

部署 mysql

mysql-rc.yaml

apiVersion: v1
kind: ReplicationController 
metadata:
  name: mysql 
spec:
  replicas: 1 
  selector:
    app: mysql 
  template: 
    metadata:
      labels:
        app: mysql 
    spec:
      containers: 
        - name: mysql 
          image: mysql:5.6 
          ports:
          - containerPort: 3306 
          env:  
          - name: MYSQL_ROOT_PASSWORD
            value: '123456'

mysql-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  type: NodePort
  ports:
    - port: 3306
  selector:
    app: mysql

启动:

kubectl apply -f mysql-rc.yaml
kubectl apply -f mysql-svc.yaml

连接测试

$ kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -p123456
If you don't see a command prompt, try pressing enter.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| HPE_APP            |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

你可能感兴趣的:(Kubernetes 示例 - 部署 mysql 服务)