<p>my pod stays in pending state after kubectl apply. I am currently trying to deploy 3 services which are postgres database,api server and the ui of application.The postgres pod is running fine but the remaining 2 services are stuck in pending state.</p>

<p>I tried creating yaml files like this</p>

<p>api server persistant volume</p>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: api-initdb-pv-volume
  labels:
    type: local
    app: api
spec:
  storageClassName: manual
  capacity:
    storage: 1Mi
  accessModes:
    - ReadOnlyMany
  hostPath:
    path: "/home/vignesh/pagedesigneryamls/api"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: api-initdb-pv-claim-one
  labels:
    app: api
spec:
  storageClassName: manual
  accessModes:
    - ReadOnlyMany
  resources:
    requests:
      storage: 1Mi
</code></pre>

<p>api server </p>

<pre><code>
apiVersion: v1
kind: Service
metadata:
  name: apiserver
  labels:
    app: apiserver
spec:

  ports:
  - name: apiport
    port: 8000
    targetPort: 8000

  selector:
    app: apiserver
    tier: backend    

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: apiserver
  labels:
    app: apiserver
spec:
  selector:
    matchLabels:
      app: apiserver
      tier: backend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: apiserver
        tier: backend
    spec:

      containers:
      - image: suji165475/devops-sample:wootz-backend
        name: apiserver
        ports:
        - containerPort: 8000
          name: myport
        volumeMounts:
        - name: api-persistent-storage-one
          mountPath: /usr/src/app
        - name: api-persistent-storage-two
          mountPath: /usr/src/app/node_modules  
      volumes:
      - name: api-persistent-storage-one
        persistentVolumeClaim:
          claimName: api-initdb-pv-claim-one
      - name: api-persistent-storage-two
        persistentVolumeClaim:
          claimName: api-initdb-pv-claim-two 

</code></pre>

<p>docker-compose file (just for refernce)</p>

<pre><code>
version: "3"

services:
  pg_db:
    image: postgres
    networks: 
      - wootzinternal
    ports:
      - 5432
    environment:
      - POSTGRES_PASSWORD=password
      - POSTGRES_USER=postgres
      - POSTGRES_DB=wootz
    volumes:
      - wootz-db:/var/lib/postgresql/data
  apiserver:
    image: wootz-backend
    volumes:
      - ./api:/usr/src/app
      - /usr/src/app/node_modules
    build:
      context: ./api
      dockerfile: Dockerfile
    networks: 
      - wootzinternal
    depends_on:
      - pg_db
    ports:
      -  '8000:8000'
  ui:
    image: wootz-frontend
    volumes:
      - ./client:/usr/src/app
      - /usr/src/app/node_modules
    build:
      context: ./client
      dockerfile: Dockerfile
    networks:
      - wootzinternal
    ports:
      - '80:3000'

volumes:
  wootz-db:

networks:
  wootzinternal:
    driver: bridge

</code></pre>

<p>when I tried kubectl apply on the api server yaml file, the pod for the api server was stuck in pending state for ever.how do i solve this.</p>

Swetha Swaminathan
<p>For your future questions, if you need to get more information on what is happening you should be using <code>kubectl describe pod_name</code> as this would give you and us more information and would increase a chance for a proper answer. I used your yaml and after describing the pod:</p>

<pre><code>persistentvolumeclaim "api-initdb-pv-claim-two" not found
</code></pre>

<p>After adding second one:</p>

<pre><code>pod has unbound PersistentVolumeClaims (repeated 3 times)
</code></pre>

<p>After you add the second PV it should start working. </p>

<p>You have two persistent volume claims and only one persistent volume. You can't bind two PVC to a PV. So in this case you need to add another PV and another PVC to the manifests. </p>

<p>You can read more about it <a href="https://groups.google.com/forum/#!topic/kubernetes-users/6A1ZwSYkG8I" rel="nofollow noreferrer">here</a>. </p>

<blockquote>
  <p>A PersistentVolume (PV) is an atomic abstraction.  You can not 
  subdivide it across multiple claims.</p>
</blockquote>

<p>More information about Persistent Volumes and how they work can be found in the official <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#introduction" rel="nofollow noreferrer">documentation</a>.</p>

<p>Also if you are trying to deploy PostgresSQL <a href="https://severalnines.com/blog/using-kubernetes-deploy-postgresql" rel="nofollow noreferrer">here</a> is a good guide on how to do that. And another one which will be easier as it is using managed Kubernetes service - <a href="https://portworx.com/run-ha-postgresql-gke/" rel="nofollow noreferrer">how to run HA PostgreSQL on GKE</a>. </p>
