部署 mysql
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'
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
type: NodePort
ports:
- port: 3306
nodePort: 30060
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
kubectl get rc,svc
mysql -h 10.109.17.0 -P 3306 -uroot -p123456
外部连接:mysql -h 10.2.33.77 -P 30060 -uroot -p123456