Wordpress Example

Wordpress is a free and open-source content management system based on PHP and MySQL..

How to run

  • Save this example to file, e.g wordpress.yaml
  • Change host names myapp.kuber.host to domain of your namespace (see your domains)
  • Run with kubectl apply -f wordpress.yaml

Example Screenshot

wordpress.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mysql-storage
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 300Mi

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wordpress-storage
  labels:
    app: wordpress
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 200Mi

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      securityContext:
        fsGroup: 27
        runAsUser: 27
      containers:
      - image: centos/mysql-57-centos7:latest
        name: mysql
        #command: ["sh", "-c"]
        #args: ["rm -rf /var/lib/mysql/* && container-entrypoint run-mysqld"]
        #args: ["sleep 10000"]
        resources:
          requests: { memory: "50Mi", cpu: "100m" }
          limits: { memory: "850Mi", cpu: "100m" }
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: admin
        - name: MYSQL_KEY_BUFFER_SIZE
          value: "2097152"
        - name: MYSQL_SORT_BUFFER_SIZE
          value: "32768"
        - name: MYSQL_READ_BUFFER_SIZE
          value: "8200"
        - name: MYSQL_INNODB_BUFFER_POOL_SIZE
          value: "16777216"
        - name: MYSQL_INNODB_LOG_FILE_SIZE
          value: "5M"
        - name: MYSQL_INNODB_LOG_BUFFER_SIZE
          value: "4194304"
        - name: MYSQL_MAX_CONNECTIONS
          value: "30"
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
          - name: mysql-persistent-storage
            mountPath: /var/lib/mysql
        readinessProbe:
          exec:
            command:
              - /opt/rh/rh-mysql57/root/usr/bin/mysql
              - "--user=root"
              - "--password=admin"
              - "--host=127.0.0.1"
              - "--execute=select database();"
              - "mysql"
          initialDelaySeconds: 5
          timeoutSeconds: 15
          periodSeconds: 5
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-storage

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      automountServiceAccountToken: false
      containers:
      - image: wordpress:4-apache
        name: wordpress
        resources:
          limits: { memory: "100Mi", cpu: "100m" }
        env:
        - name: WORDPRESS_DB_HOST
          value: mysql
        - name: WORDPRESS_DB_PASSWORD
          value: admin
        - name: WORDPRESS_DEBUG
          value: "1"
        command: ["bash", "-c"]
        args: ["rm -rf /var/www/html/lost+found && docker-entrypoint.sh apache2-foreground"]
        ports:
        - containerPort: 80
          name: wordpress
        volumeMounts:
          - name: wordpress-storage
            mountPath: /var/www/html
        readinessProbe:
          exec:
            command:
              - curl
              - -v
              - localhost
          initialDelaySeconds: 10
          timeoutSeconds: 5
          periodSeconds: 15
      volumes:
        - name: wordpress-storage
          persistentVolumeClaim:
            claimName: wordpress-storage

---
apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
#  type: LoadBalancer
  ports:
    - port: 80
  selector:
    app: wordpress

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

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: wordpress-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    certmanager.k8s.io/cluster-issuer: letsencrypt
spec:
  tls:
    - hosts:
      - myapp.kuber.host
      secretName: myapp-kuber-host
  rules:
  - host: myapp.kuber.host
    http:
      paths:
      - path: /
        backend:
          serviceName: wordpress
          servicePort: 80