mysql pod on k8s

** create a mysql instance **

apiVersion: v1
kind: Pod
metadata:
  name: mysql
spec:
  containers:
  - image: mysql:5.6
    name: mysql
    env:
    # Use secret in real usage
    - name: MYSQL_ROOT_PASSWORD
      value: password
    ports:
    - containerPort: 3306
      name: mysql

Access the mysql inside the cluster

exec directly

k exec mysql -it -- sh
mysql -u root -ppassword

boot a new pod

k run -it --rm --image=mysql:5.6 mysql-client -- mysql -h <pod-ip> -u root -p <password>

Access the mysql from outside world [using NodePort Service ]

yum -y localinstall MySQL-client-5.6.39-1.el6.x86_64.rpm
 k label po mysql mysql=mysql
k expose pod mysql --port=3306  --target-port=3306  --type=NodePort 
mysql -h 10.254.21.3 -P 30607  -u root -p