07 Pod Configuration using a YAML Deployment

Navigation Menu

In this chapter we will become more familiar with Kubectl commands and run mysql database along with phpmyadmin

Create 2 Yaml Files for MySQL and PhpMyAdmin Docker Installation

mysql-db.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/tmp/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-service
  labels:
    app: mysql
spec:
    selector:
      app: mysql
    ports:
      - port: 3306
    clusterIP: None
---
apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  volumes:
    - name: mysql-pv-storage
      persistentVolumeClaim:
       claimName: mysql-pv-claim
  containers:
    - image: mysql/mysql-server:latest 
      name: mysql  
      ports:
        - containerPort: 3306
          name: mysql
      volumeMounts:
        - mountPath: /var/lib/mysql
          name: mysql-pv-storage
      env:
        - name: MYSQL_ROOT_PASSWORD   
          value: "password"

phpmyadmin.yaml

---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: phpmyadmin
  name: phpmyadmin
spec:
  ports:
    - port: 80
      targetPort: 80
  selector:
    name: phpmyadmin
  type: NodePort
---
apiVersion: v1
kind: Pod
metadata:
  name: phpmyadmin
  labels:
    name: phpmyadmin
spec:
  containers:
    - name: phpmyadmin
      image: phpmyadmin/phpmyadmin
      env:
        - name: PMA_HOST
          value: mysql-service
      ports:
        - containerPort: 80
          name: phpmyadmin
Deploy both the yaml files using Kubectl
oracle@oracle:~/kube$ kubectl create -f mysql-db.yaml
persistentvolume/mysql-pv-volume created
persistentvolumeclaim/mysql-pv-claim created
service/mysql-service created
pod/mysql created
oracle@oracle:~/kube$ kubectl create -f phpmyadmin.yaml
service/phpmyadmin created
pod/phpmyadmin created
oracle@oracle:~/kube$ kubectl get services phpmyadmin
NAME         TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
phpmyadmin   NodePort   10.96.166.79           80:31288/TCP   28s
check on which IPs these are running use get Nodes
oracle@oracle:~/kube$ kubectl get nodes
NAME              STATUS   ROLES   AGE   VERSION
129.213.148.25    Ready    node    20h   v1.11.1
129.213.39.155    Ready    node    20h   v1.11.1
132.145.175.245   Ready    node    20h   v1.11.1

Effectively phpMyAdmin should now be running on Node IP:Service Port

http://129.213.148.25:31288   
http://129.213.39.155:31288    
http://132.145.175.245:31288    
Reality Check

View in Kubernetes Dashboard

Reference

https://docs.oracle.com/cd/E52668_01/E88884/html/kubectl-pod-yaml-deployments.html