Where WordPress install is located on Google Cloud Kubernetes Cluster

Viewed 312

I have Wordpress run as an app container in Google Cloud Kubernetes Cluster. I've ruined my site a bit by wrong modifications of theme's functions.php file. So now i would like to remove my bad code to make site working. Hoever I can not find where Wordpress is located. As all I need is to remove couple lines of PHP code I thought it might be easier to do it right from the SSH command line without playing with SFTP and keys (sorry I'm newby in WordPress/Sites in general) This how it looks like in Google Cloud Console

Wordpress install

Wordpress App

Google Cloud Console: my cluster

Google Cloud Console screenshot

I'm connecting to cluster through SSH by pressing "Connect" button. And... tada! I see NO "/var/www/html" in "var" folder! ".../www/html" folder is not exists/visible even under root

Contents on VAR folder

Can someone help me with finding WordPress install, please :)

Here is the output for $ kubectl describe pod market-engine-wordpress-0 mypod -n kalm-system comand

Name:         market-engine-wordpress-0
Namespace:    kalm-system
Priority:     0
Node:         gke-cluster-1-default-pool-6c5a3d37-sx7g/10.164.0.2
Start Time:   Thu, 25 Jun 2020 17:35:54 +0300
Labels:       app.kubernetes.io/component=wordpress-webserver
              app.kubernetes.io/name=market-engine
              controller-revision-hash=market-engine-wordpress-b47df865b
              statefulset.kubernetes.io/pod-name=market-engine-wordpress-0
Annotations:  <none>
Status:       Running
IP:           10.36.0.17
IPs:
  IP:           10.36.0.17
Controlled By:  StatefulSet/market-engine-wordpress
Containers:
  wordpress:
    Container ID:   docker://32ee6d8662ff29ce32a5c56384ba9548bdb54ebd7556de98cd9c401a742344d6
    Image:          gcr.io/cloud-marketplace/google/wordpress:5.3.2-20200515-193202
    Image ID:       docker-pullable://gcr.io/cloud-marketplace/google/wordpress@sha256:cb4515c3f331e0c6bcca5ec7b12d2f3f039fc5cdae32f0869abf19238d580575
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Mon, 29 Jun 2020 15:37:38 +0300
      Finished:     Mon, 29 Jun 2020 15:40:08 +0300
    Ready:          False
    Restart Count:  774

  Environment:
      POD_NAME:       market-engine-wordpress-0 (v1:metadata.name)
      POD_NAMESPACE:  kalm-system (v1:metadata.namespace)
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-4f6xq (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  market-engine-wordpress-pvc:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  market-engine-wordpress-pvc-market-engine-wordpress-0
    ReadOnly:   false
  apache-config:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      market-engine-wordpress-config
    Optional:  false
  config-map:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      market-engine-wordpress-config
    Optional:  false
  default-token-4f6xq:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-4f6xq
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                       From                                               Message
  ----     ------     ----                      ----                                               -------
  Warning  Unhealthy  8m33s (x9023 over 2d15h)  kubelet, gke-cluster-1-default-pool-6c5a3d37-sx7g  Readiness probe failed: HTTP probe failed with statuscode: 500
  Warning  BackOff    3m30s (x9287 over 2d15h)  kubelet, gke-cluster-1-default-pool-6c5a3d37-sx7g  Back-off restarting failed container
1 Answers

As you described, your application is crashing because of a change you have made in the code. This is making your website to fail and your pod is configured to check if the website is running fine and if not, the container will be restarted. The configuration that makes it happen is the LivenessProbe and the ReadinessProbe.

The problem here is that prevents you from fixing the problem.

The good news is that your data is saved under /var/www/html and this directory is on a external storage.

So, the easiest solution is to create a new pod and attach this storage to this pod. Problem is that this storage cannot be mounted on more than one container at the same time.

Creating this new pod, requires you to temporarily remove your wordpress pod. I know, it may be scary but we will recreate it after.

I reproduced your scenario and tested these steps. So Let's start. (All steps as mandatory)

Before we start, let's save your market-engine-wordpress manifest:

$ kubectl get statefulsets market-engine-wordpress -o yaml > market-engine-wordpress.yaml

Delete your wordpress statefulset:

$ kubectl delete statefulsets market-engine-wordpress

This commands delete the instruction that creates your wordpress pod.

Now, let's create a new pod using the following manifest:

apiVersion: v1
kind: Pod
metadata:
  name: fenix 
  namespace: kalm-system  
spec:
  volumes:
  - name: market-engine-wordpress-pvc
    persistentVolumeClaim:
      claimName: market-engine-wordpress-pvc-market-engine-wordpress-0    
  containers:
  - name: ubuntu
    image: ubuntu
    command: ['sh', '-c', "sleep 36000"]
    volumeMounts:
    - mountPath: /var/www/html
      name: market-engine-wordpress-pvc
      subPath: wp

To create this pod, save this content in a file as fenix.yaml and run the following command:

$ kubectl apply -f fenix.yaml

Check if the pod is ready:

$ kubectl get pods fenix
NAME         READY   STATUS    RESTARTS   AGE
fenix        1/1     Running   0          5m

From this point, you can connect to this pod and fix your functions.php file:

$ kubectl exec -ti fenix -- bash
root@fenix:/# cd /var/www/html/wp-includes/
root@fenix:/var/www/html/wp-includes# 

When you are done fixing your code, we can delete this pod and re-create your wordpress pod.

$ kubectl delete pod fenix 
pod "fenix" deleted
$ kubectl apply -f market-engine-wordpress.yaml 
statefulset.apps/market-engine-wordpress created

Check if the pod is ready:

$ kubectl get pod market-engine-wordpress-0 
NAME                        READY   STATUS    RESTARTS   AGE
market-engine-wordpress-0   2/2     Running   0          97s

If you need to exec into the wordpress container, your application uses the concept of multi-container pod and connecting to the right container requires you to indicate what container you want to connect.

To check how many containers and the name of which one you can run kubectl get pod mypod -o yaml or run kubectl describe pod mypod.

To finally exec into it, use the following command:

$ kubectl exec -ti market-engine-wordpress-0 -c wordpress -- bash
root@market-engine-wordpress-0:/var/www/html# 
Related