Deploy Nginx and Phpfpm on Kubernetes Failed With No Details

Hi,

I’ve done this task twice and both times it failed with no details about what failed.

I tried to get this reviewed but no one reviewed it. The work I did was:

# Create Config Map YAML
cat > cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
data:
  nginx.conf: |
    user nginx;
    worker_processes  1;
    events {
      worker_connections  10240;
    }
    http {
      server {
        listen 8096;
        server_name localhost;
        location / {
          root /var/www/html;
          index index.html index.htm index.php;
        }
      }
    }

Close the file with control + d i.e. ^D

# Create Config Map
k apply  -f cm.yaml
configmap/nginx-config create
# Create Pod YAML
cat > pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx-phpfpm
  labels:
    app: nginx-phpfpm
spec:
  containers:
  - image: nginx:latest
    name: nginx-container
    ports:
    - containerPort: 8096
    volumeMounts:
    - mountPath: /var/www/html
      name: shared-files
    - mountPath: /etc/nginx/nginx.conf
      name: nginx-config-volume
      subPath: nginx.conf
  - image: php:7.2-fpm
    name: php-fpm-container
    ports:
    - containerPort: 8096
    volumeMounts:
    - mountPath: /var/www/html
      name: shared-files
  volumes:
  - name: shared-files
    emptyDir:
      sizeLimit: 128Mi
  - name: nginx-config-volume
    configMap:
      name: nginx-config
      items:
      - key: nginx.conf
        path: nginx.conf

Close the file with control + d i.e. ^D

# Create Pod
k apply -f pod.yaml
pod/nginx-phpfpm created
# Check Pods
k get pods -o wide
NAME           READY   STATUS    RESTARTS   AGE   IP           NODE                      NOMINATED NODE   READINESS GATES
nginx-phpfpm   2/2     Running   0          59s   10.244.0.5   kodekloud-control-plane   <none>           <none>
# Create NodePort YAML
cat > svc.yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: nginx-phpfpm
  name: nginx-phpfpm
spec:
  ports:
  - port: 8096
    protocol: TCP
    targetPort: 8096
    nodePort: 30012
  selector:
    app: nginx-phpfpm
  type: NodePort
status:
  loadBalancer: {}

Close the file with control + d i.e. ^D

# Create NodePort
k apply -f nodeport.yaml
service/nginx-phpfpm created
# Get homepage content
cat /opt/index.php
It works!
# Create homepage
k exec nginx-phpfpm -c php-fpm-container -- bash -c 'echo "It works!" > /var/www/html/index.html'
k exec nginx-phpfpm -c php-fpm-container -- cat /var/www/html/index.html
It works!

Testing by clicking the App button shows it was working as it displayed the text It works! in the browser.

Can someone at KK have a look please, I either should have passed this task or gotten details as to why it failed.

Thanks.

Ah I just tried it again for a third time with the exact same settings and it worked this time.