0

I am trying to deploy a WordPress site with MySQL database using kops. When I run these YAML files the PVC is in pending state and doesn't create the volume on ebs. I first thought it was because of the availability zone in the storage YAML file but I have tried all the possible combinations but no luck.

Storage class

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: standard
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2 
  zone: us-east-2a
  iopsPerGB: "10"
reclaimPolicy: Delete
allowVolumeExpansion: false

Persistent volume claim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wp-pv-claim
  labels:
    app: wordpress
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

Deployment:

apiVersion: apps/v1 
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
          value: 123a
        ports:
        - containerPort: 80
          name: wordpresss
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
      volumes:
      - name: wordpress-persistent-storage
        persistentVolumeClaim:
          claimName: wp-pv-claim

Service:

apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    app: wordpress
    tier: frontend
  type: NodePort
  ports:
    - nodePort: 30007 
      port: 80
      targetPort: 80

I am creating a cluster using this command:

kops create cluster \
--node-count=1 \
--node-size=t2.micro \
--master-size=t2.small \
--zones=us-east-2a \
--name=${KOPS_CLUSTER_NAME}
  • Did the same issue occurs, if you will use bigger size master like `--master-size t2.large` when creating cluster? – PjoterS Oct 06 '20 at 09:13
  • If I use us-east-2a as the zone it work fine with mysql pvc but not with wordpress pvc. I haven't tried with t2.large. Secondly, I am using nodeport as a service in wordpress (just stating it as it might have something to do with it too) –  Oct 06 '20 at 11:47
  • Service shouldnt affect. Could you share your YAMLs? Maybe somewhere is a typo or your cluster dont have enough resources? Also what you have when you use `kubectl describe pvc wp-pv-claim`, Im curious abut this pending state. As for quick test, if you would remove mysql pv/pvc and create for wordpress? Will pv and pvc be created? – PjoterS Oct 06 '20 at 12:08
  • I will share the wordpress complete file, as far as my understanding there is something wrong with the storage file as when I remove the storage file and run it locally pvc actually works. If storage class zone is set to `us-east-2b` for wordpress and `us-east-2a` for mysql the volumn bound but then wordpress pod go to `pending` state while mysql pod is healthy –  Oct 06 '20 at 12:49
  • @PjoterS I have added service and deployment yaml files –  Oct 06 '20 at 13:17

1 Answers1

1

As I suspected in my first comment, you don't have enough resocurces to run mysql and wordpress.

If you will check Amazon instance types you will see that t2.nano and t2.small have quite low resources.

Name    vCPUs   RAM (GiB)   
t2.nano     1   0.5     
t2.small    1   2.0

Also as you mention in your last comment:

mysql the volumn bound but then wordpress pod go to pending state while mysql pod is healthy

It's because cluster do not have enough resources to start pod.

If you will use kubectl describe pod <wordpress-pod-name> you would get output similar to:

Warning FailedScheduling 4s (x4 over 92s) default-scheduler 0/2 nodes are available: 1 Insufficient cpu, 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.

Cluster with that amount of resources won't be able to run wordpress and mysql. Please keep in mind that also kubernetes default pods are running, to check which one, you can run kubectl get pods -A.

Solution:

  • Create new kops cluster using instance t2.large with more resources
  • Add node to your kops cluster. You can check this stackoverflow thread
PjoterS
  • 12,841
  • 1
  • 22
  • 54