Kops - unable to bound to storage class using pvc

475 views Asked by At

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}
1

There are 1 answers

0
PjoterS On BEST ANSWER

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