Skip to content

Instantly share code, notes, and snippets.

@p4tin
Created November 30, 2018 16:18
Show Gist options
  • Save p4tin/bbdda81b570f017ff54b1af4aed0ccdc to your computer and use it in GitHub Desktop.
Save p4tin/bbdda81b570f017ff54b1af4aed0ccdc to your computer and use it in GitHub Desktop.
Wordpress Kubernetes Cluster

Kubernetes Wordpress installation

Use minikube to test with

  • on macos: ** brew cask install minikube ** minikube start

Start the cluster and scale:

  • kubectl create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD
  • kubectl get secrets
  • kubectl create -f mysql-deployment.yaml
  • kubectl create -f wordpress-deployment.yaml
  • kubectl get pv
  • kubectl get pvc
  • kubectl get pods
  • kubectl get services
  • minikube service wordpress --url (Get URL for wordpress - start install and have fun)

Scale Wordpress and mysql:

  • kubectl scale --replicas X deployments wordpress-mysql
  • kubectl scale --replicas X deployments wordpress

Cleanup

  • kubectl delete secret mysql-pass
  • kubectl delete deployment -l app=wordpress
  • kubectl delete service -l app=wordpress
  • kubectl delete pvc -l app=wordpress
  • kubectl delete pv -l app=wordpress

Stop minicube

  • minikube stop
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: mysql-pv
labels:
app: wordpress
spec:
storageClassName: manual
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data/mysql"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: wordpress
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
nodePort: 31476
selector:
app: wordpress
tier: frontend
type: LoadBalancer
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: wp-pv
labels:
app: wordpress
spec:
storageClassName: manual
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data/wordpress"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
labels:
app: wordpress
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: wordpress
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: frontend
spec:
containers:
- image: wordpress:4.8-apache
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mysql
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 80
name: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wp-pv-claim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment