title: How to run a simple php hello world application using Kubernetes
body: <p>I'm trying to deploy and run a simple PHP application that will only show a <code>Hello World</code> message through my Kubernetes cluster which is only a master node cluster, unfortunately, I can't do that.</p>
  
  <p>I'm describing my project structure -
  I have a root project directory called <code>kubernetes-test</code> and under that directory, I have 3 <code>yaml</code> files and one directory called <code>code</code> under that directory I have a PHP file called <code>index.php</code></p>
  
  <p><strong>hello-world-service.yaml:</strong></p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: nginx
    labels:
      tier: backend
  spec:
    selector:
      app: nginx
      tier: backend
    type: NodePort
    ports:
    - nodePort: 30500
      port: 80
      targetPort: 80
  </code></pre>
  
  <p><strong>nginx-deployment.yaml</strong></p>
  
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: nginx
    labels:
      tier: backend
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: nginx
        tier: backend
    template:
      metadata:
        labels:
          app: nginx
          tier: backend
      spec:
        volumes:
        - name: code
          hostPath:
            path: /code
        - name: config
          configMap:
            name: nginx-config
            items:
            - key: config
              path: site.conf
        containers:
        - name: nginx
          image: nginx:1.7.9
          ports:
          - containerPort: 80
          volumeMounts:
          - name: code
            mountPath: /var/www/html
          - name: config
            mountPath: /etc/nginx/conf.d
  </code></pre>
  
  <p><strong>php-deployment.yaml</strong></p>
  
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: php
    labels:
      tier: backend
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: php
        tier: backend
    template:
      metadata:
        labels:
          app: php
          tier: backend
      spec:
        volumes:
        - name: code
          hostPath:
            path: /code
        containers:
        - name: php
          image: php:7-fpm
          volumeMounts:
          - name: code
            mountPath: /var/www/html
  </code></pre>
  
  <p><strong>code/index.php</strong></p>
  
  <pre><code>&lt;?php
    echo 'Hello World';
  </code></pre>
  
  <p>Above all those things I've found through the internet.</p>
  
  <p>When I ran this command <code>kubectl get pods</code>
  then the status is showing <code>ContainerCreating</code> forever for the Nginx deployment like this</p>
  
  <pre><code>NAME                    READY   STATUS              RESTARTS   AGE
  nginx-64c9df788f-jxwzx   0/1     ContainerCreating    0          12h
  php-55f974bb4-qvv9x      1/1     Running              0          25s
  </code></pre>
  
  <p><strong>Command:</strong> <code>kubectl describe pod nginx-64c9df788f-jxwzx</code></p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Name:           nginx-64c9df788f-jxwzx
  Namespace:      default
  Priority:       0
  Node:           bablu-node/192.168.43.123
  Start Time:     Mon, 11 May 2020 03:20:58 +0600
  Labels:         app=nginx
                  pod-template-hash=64c9df788f
                  tier=backend
  Annotations:    &lt;none&gt;
  Status:         Pending
  IP:             
  IPs:            &lt;none&gt;
  Controlled By:  ReplicaSet/nginx-64c9df788f
  Containers:
    nginx:
      Container ID:   
      Image:          nginx
      Image ID:       
      Port:           80/TCP
      Host Port:      0/TCP
      State:          Waiting
        Reason:       ContainerCreating
      Ready:          False
      Restart Count:  0
      Environment:    &lt;none&gt;
      Mounts:
        /etc/nginx/conf.d from config (rw)
        /var/run/secrets/kubernetes.io/serviceaccount from default-token-l2zp2 (ro)
        /var/www/html from code (rw)
  Conditions:
    Type              Status
    Initialized       True 
    Ready             False 
    ContainersReady   False 
    PodScheduled      True 
  Volumes:
    code:
      Type:          HostPath (bare host directory volume)
      Path:          /code
      HostPathType:  
    config:
      Type:      ConfigMap (a volume populated by a ConfigMap)
      Name:      nginx-config
      Optional:  false
    default-token-l2zp2:
      Type:        Secret (a volume populated by a Secret)
      SecretName:  default-token-l2zp2
      Optional:    false
  QoS Class:       BestEffort
  Node-Selectors:  &lt;none&gt;
  Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                   node.kubernetes.io/unreachable:NoExecute for 300s
  Events:
    Type     Reason       Age                    From                 Message
    ----     ------       ----                   ----                 -------
    Warning  FailedMount  31m (x14 over 147m)    kubelet, bablu-node  Unable to attach or mount volumes: unmounted volumes=[config], unattached volumes=[default-token-l2zp2 code config]: timed out waiting for the condition
    Warning  FailedMount  16m (x82 over 167m)    kubelet, bablu-node  MountVolume.SetUp failed for volume "config" : configmap "nginx-config" not found
    Warning  FailedMount  6m53s (x44 over 165m)  kubelet, bablu-node  Unable to attach or mount volumes: unmounted volumes=[config], unattached volumes=[code config default-token-l2zp2]: timed out waiting for the condition
    Warning  FailedMount  2m23s (x10 over 163m)  kubelet, bablu-node  Unable to attach or mount volumes: unmounted volumes=[config], unattached volumes=[config default-token-l2zp2 code]: timed out waiting for the condition
  </code></pre>
  
  <p>Command: <code>kubectl get events -n default</code></p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>LAST SEEN   TYPE      REASON              OBJECT                       MESSAGE
  18m         Warning   FailedMount         pod/nginx-64c9df788f-jxwzx   MountVolume.SetUp failed for volume "config" : configmap "nginx-config" not found
  8m45s       Warning   FailedMount         pod/nginx-64c9df788f-jxwzx   Unable to attach or mount volumes: unmounted volumes=[config], unattached volumes=[code config default-token-l2zp2]: timed out waiting for the condition
  4m15s       Warning   FailedMount         pod/nginx-64c9df788f-jxwzx   Unable to attach or mount volumes: unmounted volumes=[config], unattached volumes=[config default-token-l2zp2 code]: timed out waiting for the condition
  33m         Warning   FailedMount         pod/nginx-64c9df788f-jxwzx   Unable to attach or mount volumes: unmounted volumes=[config], unattached volumes=[default-token-l2zp2 code config]: timed out waiting for the condition
  18m         Normal    Scheduled           pod/php-55f974bb4-qvv9x      Successfully assigned default/php-55f974bb4-qvv9x to bablu-node
  18m         Normal    Pulled              pod/php-55f974bb4-qvv9x      Container image "php:7-fpm" already present on machine
  18m         Normal    Created             pod/php-55f974bb4-qvv9x      Created container php
  18m         Normal    Started             pod/php-55f974bb4-qvv9x      Started container php
  18m         Normal    SuccessfulCreate    replicaset/php-55f974bb4     Created pod: php-55f974bb4-qvv9x
  18m         Normal    ScalingReplicaSet   deployment/php               Scaled up replica set php-55f974bb4 to 1
  </code></pre>
  
  <p>Can anyone please help me?
  Thanks in advance!!</p>