问:
Error when trying to creating a StateFulSet: 0/9 nodes are available: 9 pod has unbound immediate PersistentVolumeClaims
I am trying to replace a deployment with StateFulSet having a persistent volume.

A quick summary:

The deployment was ran successfully for a web app having front end and backend (MySQL)

Then we deleted the deployment.

Wrote down the YAML file for Statefulset w.r.t backend.

applied the statefulset YAML.

However, the pod for MySQL does not come up and always goes into 'CrashLoopBackOff' state.

Request your help to understand the issue.

I am putting all the logs below - it is lengthy but hopefully it will help to better understand the entire scenario.

Original config:

```<code>~] $ kubectl get all
NAME                                  READY   STATUS    RESTARTS      AGE
pod/gowebapp-54f6cd5f64-6xl99         1/1     Running   0             73s
pod/gowebapp-54f6cd5f64-fn6sc         1/1     Running   3 (83s ago)   2m8s
pod/gowebapp-mysql-7c4ddfccdf-2x27f   1/1     Running   0             107s

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/gowebapp         ClusterIP   100.xx.xxx.xxx   <none>        8080/TCP   2m8s
service/gowebapp-mysql   ClusterIP   100.xx.xx.xx     <none>        3306/TCP   2m30s

NAME                             READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/gowebapp         2/2     2            2           2m20s
deployment.apps/gowebapp-mysql   1/1     1            1           2m30s

NAME                                        DESIRED   CURRENT   READY   AGE
replicaset.apps/gowebapp-54f6cd5f64         2         2         2       2m8s
replicaset.apps/gowebapp-5744cdff7d         0         0         0       2m20s
replicaset.apps/gowebapp-mysql-6b685888cd   0         0         0       2m30s
replicaset.apps/gowebapp-mysql-7c4ddfccdf   1         1         1       107s
[~] $

</code>```

Aim of the exercise: To replace the deployment with StatefulSet having a persistent volume.

```<code>*Step 1: Delete the existing deployment for MySQL.*

[~] $ kubectl delete deployment gowebapp-mysql
deployment.apps "gowebapp-mysql" deleted

*Step 2: check the deployment no longer exists and hence the pod is terminated as well. *

[~] $ kubectl get all
NAME                                  READY   STATUS        RESTARTS        AGE
pod/gowebapp-54f6cd5f64-6xl99         1/1     Running       0               3m29s
pod/gowebapp-54f6cd5f64-fn6sc         1/1     Running       3 (3m39s ago)   4m24s
pod/gowebapp-mysql-7c4ddfccdf-2x27f   1/1     Terminating   0               4m3s

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/gowebapp         ClusterIP   100.xx.xxx.xxx   <none>        8080/TCP   4m24s
service/gowebapp-mysql   ClusterIP   100.xx.xx.xx     <none>        3306/TCP   4m46s

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/gowebapp   2/2     2            2           4m36s

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/gowebapp-54f6cd5f64   2         2         2       4m24s
replicaset.apps/gowebapp-5744cdff7d   0         0         0       4m36s
[~] $

*step 3: check the files in the working directory. Create the StatefulSet file.*

[~/gowebapp/gowebapp-mysql] $ ls -lrt
total 20
-rw-r--r-- 1 ABC!@# root 2619 Oct 24 20:24 gowebapp.sql
-rw-r--r-- 1 ABC!@# root   73 Jan  5 10:53 Dockerfile
-rw-r--r-- 1 ABC!@# root  238 Jan  5 10:54 gowebapp-mysql-service.yaml
-rw-r--r-- 1 ABC!@# root  631 Jan  5 10:54 gowebapp-mysql-deployment-lab02.yaml
-rw-r--r-- 1 ABC!@# root 1021 Jan  5 10:54 gowebapp-mysql-deployment.yaml
[~/gowebapp/gowebapp-mysql] $
[~/gowebapp/gowebapp-mysql] $ vi pv.yaml
[~/gowebapp/gowebapp-mysql] $
[~/gowebapp/gowebapp-mysql] $ cat pv.yaml

</code>```
```<code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv01
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteOnce
  hostPath:
    path: /var/pv/pv01

</code>```

[~/gowebapp/gowebapp-mysql] $ cat gowebapp-mysql-sts.yaml

```<code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: gowebapp-mysql
  labels:
    app: gowebapp-mysql
    tier: backend
spec:
  serviceName: gowebapp-mysql
  replicas: 1
  selector:
    matchLabels:
      app: gowebapp-mysql
      tier: backend
  template:
    metadata:
      labels:
        app: gowebapp-mysql
        tier: backend
    spec:
      containers:
      - name: gowebapp-mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: mypassword
        image: $REGISTRY_HOST/gowebapp-mysql:v1  *==> removing entire path on purpose*
        ports:
        - containerPort: 3306
        livenessProbe:
          tcpSocket:
            port: 3306
          initialDelaySeconds: 20
          periodSeconds: 5
          timeoutSeconds: 1
        readinessProbe:
          exec:
            command: ["mysql", "-uroot", "-XXXXXXXXXXXX", "-e", "use gowebapp; select count(*) from user"]
          initialDelaySeconds: 25
          periodSeconds: 10
          timeoutSeconds: 1
        volumeMounts:
        - name: mysql-pv
          mountPath: /var/lib/mysql
  volumeClaimTemplates:
  - metadata:
      name: mysql-pv
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 5Gi
</code>```
```<code>
*Step 4: apply the StatefulSet YAML file*

[~/gowebapp/gowebapp-mysql] $ kubectl apply -f gowebapp-mysql-sts.yaml
statefulset.apps/gowebapp-mysql created

*Step 5: check the configuration again. We observe the MySQL pod is in error. *

[~/gowebapp/gowebapp-mysql] $ kubectl get all
NAME                            READY   STATUS    RESTARTS      AGE
pod/gowebapp-54f6cd5f64-6xl99   1/1     Running   0             12m
pod/gowebapp-54f6cd5f64-fn6sc   1/1     Running   3 (12m ago)   13m
pod/gowebapp-mysql-0            0/1     Error     1 (2s ago)    19s

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/gowebapp         ClusterIP   100.xx.xxx.xxx   <none>        8080/TCP   13m
service/gowebapp-mysql   ClusterIP   100.xx.xx.xx     <none>        3306/TCP   13m

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/gowebapp   2/2     2            2           13m

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/gowebapp-54f6cd5f64   2         2         2       13m
replicaset.apps/gowebapp-5744cdff7d   0         0         0       13m

NAME                              READY   AGE
statefulset.apps/gowebapp-mysql   0/1     19s
[~/gowebapp/gowebapp-mysql] $

*Step 6: describe the MySQL pod which is in error to see the configuration and event logs.*

[~/gowebapp/gowebapp-mysql] $ kubectl describe pod gowebapp-mysql-0
Name:         gowebapp-mysql-0
Namespace:    eduk8s-labs-w19-s024
Priority:     0
Node:         ip-10-0-4-209.ec2.internal/10.0.4.209
Start Time:   Thu, 05 Jan 2023 11:07:26 +0000
Labels:       app=gowebapp-mysql
              controller-revision-hash=gowebapp-mysql-9bbb68b64
              statefulset.kubernetes.io/pod-name=gowebapp-mysql-0
              tier=backend
Annotations:  <none>
Status:       Running
IP:           100.x.x.x
IPs:
  IP:           100.x.x.x
Controlled By:  StatefulSet/gowebapp-mysql
Containers:
  gowebapp-mysql:
    Container ID:   containerd://464cfecbee1dccfb28e25adf1f12a2264ed44e30854b15ed25e5f69897e1aa15
    Image:          XXXXXXXXXXXXXXX/gowebapp-mysql:v1
    Image ID:       XXXXXXXXXXXXXXX/gowebapp-mysql@sha256:991935ad6c0c2b7e4ba7acdae920499d0a295ae29546277b42c0794efe9a95bf
    Port:           3306/TCP
    Host Port:      0/TCP
   ** State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated**
      Reason:       Error
      Exit Code:    141
      Started:      Thu, 05 Jan 2023 11:08:00 +0000
      Finished:     Thu, 05 Jan 2023 11:08:00 +0000
    Ready:          False
    Restart Count:  2
    Liveness:       tcp-socket :3306 delay=20s timeout=1s period=5s #success=1 #failure=3
    Readiness:      exec [mysql -uroot -XXXXXXX -e use gowebapp; select count(*) from user] delay=25s timeout=1s period=10s #success=1 #failure=3
    Environment:
      MYSQL_ROOT_PASSWORD:  XXXXXX
    Mounts:
      /var/lib/mysql from mysql-pv (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-kz5ds (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  mysql-pv:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mysql-pv-gowebapp-mysql-0
    ReadOnly:   false
  kube-api-access-kz5ds:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason                  Age                From                     Message
  ----     ------                  ----               ----                     -------
  **Warning  FailedScheduling        58s                default-scheduler        0/9 nodes are available: 9 pod has unbound immediate PersistentVolumeClaims.
  Warning  FailedScheduling        55s                default-scheduler        0/9 nodes are available: 9 pod has unbound immediate PersistentVolumeClaims.**
  Normal   Scheduled               53s                default-scheduler        Successfully assigned eduk8s-labs-w19-s024/gowebapp-mysql-0 to ip-10-0-4-209.ec2.internal
  Normal   SuccessfulAttachVolume  51s                attachdetach-controller  AttachVolume.Attach succeeded for volume "pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2"
  Normal   Pulling                 44s                kubelet                  Pulling image "XXXXXXXX/gowebapp-mysql:v1"
  Normal   Pulled                  42s                kubelet                  Successfully pulled image "XXXXXXXXXXXXXX/gowebapp-mysql:v1" in 1.33039215s
  Normal   Created                 19s (x3 over 42s)  kubelet                  Created container gowebapp-mysql
  Normal   Started                 19s (x3 over 42s)  kubelet                  Started container gowebapp-mysql
  Normal   Pulled                  19s (x2 over 41s)  kubelet                  Container image "XXXXXXXXXXXXXXXX/gowebapp-mysql:v1" already present on machine
  Warning  BackOff                 14s (x7 over 40s)  kubelet                  Back-off restarting failed container
[~/gowebapp/gowebapp-mysql] $

</code>```
```<code>*step 7: check that PVC exists - which it does.*

[~/gowebapp/gowebapp-mysql] $ kubectl get pvc
NAME                        STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mysql-pv-gowebapp-mysql-0   Bound    pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2   5Gi        RWO            default        104s
[~/gowebapp/gowebapp-mysql] $
[~/gowebapp/gowebapp-mysql] $
[~/gowebapp/gowebapp-mysql] $ kubectl describe persistentvolumeclaims mysql-pv-gowebapp-mysql-0
Name:          mysql-pv-gowebapp-mysql-0
Namespace:     eduk8s-labs-w19-s024
StorageClass:  default
Status:        Bound
Volume:        pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2
Labels:        app=gowebapp-mysql
               tier=backend
Annotations:   pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
               volume.beta.kubernetes.io/storage-provisioner: ebs.csi.aws.com
               volume.kubernetes.io/storage-provisioner: ebs.csi.aws.com
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      5Gi
Access Modes:  RWO
VolumeMode:    Filesystem
Used By:       gowebapp-mysql-0
Events:
  Type    Reason                 Age                  From                                                                                Message
  ----    ------                 ----                 ----                                                                                -------
  Normal  ExternalProvisioning   117s (x2 over 117s)  persistentvolume-controller                                                               waiting for a volume to be created, either by external provisioner "ebs.csi.aws.com" or manually created by system administrator
  Normal  Provisioning           117s                 ebs.csi.aws.com_ebs-csi-controller-75ddf66bf8-fw4ww_f01348ce-0cd7-4464-a3c9-49c87925167d  External provisioner is provisioning volume for claim "eduk8s-labs-w19-s024/mysql-pv-gowebapp-mysql-0"
  Normal  ProvisioningSucceeded  114s                 ebs.csi.aws.com_ebs-csi-controller-75ddf66bf8-fw4ww_f01348ce-0cd7-4464-a3c9-49c87925167d  Successfully provisioned volume pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2
[~/gowebapp/gowebapp-mysql] $

*Step 8: again, we check the configuration to see that MySQL Pod is in 'CrashLoopBackOff'*

[~/gowebapp/gowebapp-mysql] $ kubectl get all
NAME                            READY   STATUS             RESTARTS      AGE
pod/gowebapp-54f6cd5f64-6xl99   1/1     Running            0             14m
pod/gowebapp-54f6cd5f64-fn6sc   1/1     Running            3 (14m ago)   15m
pod/gowebapp-mysql-0            0/1     CrashLoopBackOff   4 (18s ago)   2m18s

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/gowebapp         ClusterIP   100.xx.xxx.xxx   <none>        8080/TCP   15m
service/gowebapp-mysql   ClusterIP   100.xx.xx.xx     <none>        3306/TCP   15m

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/gowebapp   2/2     2            2           15m

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/gowebapp-54f6cd5f64   2         2         2       15m
replicaset.apps/gowebapp-5744cdff7d   0         0         0       15m

NAME                              READY   AGE
statefulset.apps/gowebapp-mysql   0/1     2m18s
[~/gowebapp/gowebapp-mysql] $

</code>```
```<code>
- **complete set of logs:**
note: removed the entire path for registry and purposefully replaced with XXXXXXXX.

[~/gowebapp/gowebapp-mysql] $ kubectl get events
LAST SEEN   TYPE      REASON                   OBJECT                                            MESSAGE
14m         Normal    Scheduled                pod/gowebapp-54f6cd5f64-6xl99                     Successfully assigned eduk8s-labs-w19-s024/gowebapp-54f6cd5f64-6xl99 to ip-10-0-0-47.ec2.internal
14m         Normal    Pulled                   pod/gowebapp-54f6cd5f64-6xl99                     Container image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1" already present on machine
14m         Normal    Created                  pod/gowebapp-54f6cd5f64-6xl99                     Created container gowebapp
14m         Normal    Started                  pod/gowebapp-54f6cd5f64-6xl99                     Started container gowebapp
15m         Normal    Scheduled                pod/gowebapp-54f6cd5f64-fn6sc                     Successfully assigned eduk8s-labs-w19-s024/gowebapp-54f6cd5f64-fn6sc to ip-10-0-4-38.ec2.internal
15m         Normal    Pulled                   pod/gowebapp-54f6cd5f64-fn6sc                     Container image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1" already present on machine
15m         Normal    Created                  pod/gowebapp-54f6cd5f64-fn6sc                     Created container gowebapp
15m         Normal    Started                  pod/gowebapp-54f6cd5f64-fn6sc                     Started container gowebapp
15m         Warning   Unhealthy                pod/gowebapp-54f6cd5f64-fn6sc                     Readiness probe failed: Get "http://100.96.2.240:8080/": dial tcp 100.96.2.240:8080: connect: connection refused
15m         Warning   Unhealthy                pod/gowebapp-54f6cd5f64-fn6sc                     Liveness probe failed: dial tcp 100.96.2.240:8080: connect: connection refused
15m         Normal    Killing                  pod/gowebapp-54f6cd5f64-fn6sc                     Container gowebapp failed liveness probe, will be restarted
15m         Normal    SuccessfulCreate         replicaset/gowebapp-54f6cd5f64                    Created pod: gowebapp-54f6cd5f64-fn6sc
14m         Normal    SuccessfulCreate         replicaset/gowebapp-54f6cd5f64                    Created pod: gowebapp-54f6cd5f64-6xl99
16m         Normal    Scheduled                pod/gowebapp-5744cdff7d-bfvdl                     Successfully assigned eduk8s-labs-w19-s024/gowebapp-5744cdff7d-bfvdl to ip-10-0-0-47.ec2.internal
16m         Normal    Pulling                  pod/gowebapp-5744cdff7d-bfvdl                     Pulling image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1"
15m         Normal    Pulled                   pod/gowebapp-5744cdff7d-bfvdl                     Successfully pulled image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1" in 2.293354548s
15m         Normal    Created                  pod/gowebapp-5744cdff7d-bfvdl                     Created container gowebapp
15m         Normal    Started                  pod/gowebapp-5744cdff7d-bfvdl                     Started container gowebapp
14m         Normal    Killing                  pod/gowebapp-5744cdff7d-bfvdl                     Stopping container gowebapp
16m         Normal    Scheduled                pod/gowebapp-5744cdff7d-ccc45                     Successfully assigned eduk8s-labs-w19-s024/gowebapp-5744cdff7d-ccc45 to ip-10-0-4-38.ec2.internal
16m         Normal    Pulling                  pod/gowebapp-5744cdff7d-ccc45                     Pulling image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1"
15m         Normal    Pulled                   pod/gowebapp-5744cdff7d-ccc45                     Successfully pulled image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1" in 2.232486921s
15m         Normal    Created                  pod/gowebapp-5744cdff7d-ccc45                     Created container gowebapp
15m         Normal    Started                  pod/gowebapp-5744cdff7d-ccc45                     Started container gowebapp
14m         Normal    Killing                  pod/gowebapp-5744cdff7d-ccc45                     Stopping container gowebapp
16m         Normal    SuccessfulCreate         replicaset/gowebapp-5744cdff7d                    Created pod: gowebapp-5744cdff7d-ccc45
16m         Normal    SuccessfulCreate         replicaset/gowebapp-5744cdff7d                    Created pod: gowebapp-5744cdff7d-bfvdl
14m         Normal    SuccessfulDelete         replicaset/gowebapp-5744cdff7d                    Deleted pod: gowebapp-5744cdff7d-ccc45
14m         Normal    SuccessfulDelete         replicaset/gowebapp-5744cdff7d                    Deleted pod: gowebapp-5744cdff7d-bfvdl
*2m58s       Warning   FailedScheduling         pod/gowebapp-mysql-0                              0/9 nodes are available: 9 pod has unbound immediate PersistentVolumeClaims.
2m55s       Warning   FailedScheduling         pod/gowebapp-mysql-0                              0/9 nodes are available: 9 pod has unbound immediate PersistentVolumeClaims.
2m53s       Normal    Scheduled                pod/gowebapp-mysql-0                              Successfully assigned eduk8s-labs-w19-s024/gowebapp-mysql-0 to ip-10-0-4-209.ec2.internal
2m51s       Normal    SuccessfulAttachVolume   pod/gowebapp-mysql-0                              AttachVolume.Attach succeeded for volume "pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2"
2m44s       Normal    Pulling                  pod/gowebapp-mysql-0                              Pulling image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1"
2m42s       Normal    Pulled                   pod/gowebapp-mysql-0                              Successfully pulled image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1" in 1.33039215s
106s        Normal    Created                  pod/gowebapp-mysql-0                              Created container gowebapp-mysql
106s        Normal    Started                  pod/gowebapp-mysql-0                              Started container gowebapp-mysql
106s        Normal    Pulled                   pod/gowebapp-mysql-0                              Container image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1" already present on machine
88s         Warning   BackOff                  pod/gowebapp-mysql-0                              Back-off restarting failed container*
16m         Normal    Scheduled                pod/gowebapp-mysql-6b685888cd-vmbbt               Successfully assigned eduk8s-labs-w19-s024/gowebapp-mysql-6b685888cd-vmbbt to ip-10-0-2-110.ec2.internal
16m         Normal    Pulling                  pod/gowebapp-mysql-6b685888cd-vmbbt               Pulling image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1"
16m         Normal    Pulled                   pod/gowebapp-mysql-6b685888cd-vmbbt               Successfully pulled image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1" in 1.353941669s
16m         Normal    Created                  pod/gowebapp-mysql-6b685888cd-vmbbt               Created container gowebapp-mysql
16m         Normal    Started                  pod/gowebapp-mysql-6b685888cd-vmbbt               Started container gowebapp-mysql
16m         Normal    Killing                  pod/gowebapp-mysql-6b685888cd-vmbbt               Stopping container gowebapp-mysql
16m         Normal    SuccessfulCreate         replicaset/gowebapp-mysql-6b685888cd              Created pod: gowebapp-mysql-6b685888cd-vmbbt
16m         Normal    SuccessfulDelete         replicaset/gowebapp-mysql-6b685888cd              Deleted pod: gowebapp-mysql-6b685888cd-vmbbt
15m         Normal    Scheduled                pod/gowebapp-mysql-7c4ddfccdf-2x27f               Successfully assigned eduk8s-labs-w19-s024/gowebapp-mysql-7c4ddfccdf-2x27f to ip-10-0-2-110.ec2.internal
15m         Normal    Pulled                   pod/gowebapp-mysql-7c4ddfccdf-2x27f               Container image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1" already present on machine
15m         Normal    Created                  pod/gowebapp-mysql-7c4ddfccdf-2x27f               Created container gowebapp-mysql
15m         Normal    Started                  pod/gowebapp-mysql-7c4ddfccdf-2x27f               Started container gowebapp-mysql
11m         Normal    Killing                  pod/gowebapp-mysql-7c4ddfccdf-2x27f               Stopping container gowebapp-mysql
11m         Warning   Unhealthy                pod/gowebapp-mysql-7c4ddfccdf-2x27f               Readiness probe failed: Warning: Using a password on the command line interface can be insecure....
15m         Normal    SuccessfulCreate         replicaset/gowebapp-mysql-7c4ddfccdf              Created pod: gowebapp-mysql-7c4ddfccdf-2x27f
16m         Normal    ScalingReplicaSet        deployment/gowebapp-mysql                         Scaled up replica set gowebapp-mysql-6b685888cd to 1
16m         Normal    ScalingReplicaSet        deployment/gowebapp-mysql                         Scaled down replica set gowebapp-mysql-6b685888cd to 0
15m         Normal    ScalingReplicaSet        deployment/gowebapp-mysql                         Scaled up replica set gowebapp-mysql-7c4ddfccdf to 1
2m59s       Normal    SuccessfulCreate         statefulset/gowebapp-mysql                        create Claim mysql-pv-gowebapp-mysql-0 Pod gowebapp-mysql-0 in StatefulSet gowebapp-mysql success
2m59s       Normal    SuccessfulCreate         statefulset/gowebapp-mysql                        create Pod gowebapp-mysql-0 in StatefulSet gowebapp-mysql successful
16m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled up replica set gowebapp-5744cdff7d to 2
15m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled up replica set gowebapp-54f6cd5f64 to 1
14m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled down replica set gowebapp-5744cdff7d to 1
14m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled up replica set gowebapp-54f6cd5f64 to 2
14m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled down replica set gowebapp-5744cdff7d to 0
2m59s       Normal    ExternalProvisioning     persistentvolumeclaim/mysql-pv-gowebapp-mysql-0   waiting for a volume to be created, either by external provisioner "ebs.csi.aws.com" or manually created by system administrator
2m59s       Normal    Provisioning             persistentvolumeclaim/mysql-pv-gowebapp-mysql-0   External provisioner is provisioning volume for claim "eduk8s-labs-w19-s024/mysql-pv-gowebapp-mysql-0"
2m56s       Normal    ProvisioningSucceeded    persistentvolumeclaim/mysql-pv-gowebapp-mysql-0   Successfully provisioned volume pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2
[
</code>```

~/gowebapp/gowebapp-mysql] $

Tried to check the logs and other Stack overflow questions for similar error messages but did not help.

The expectation is to setup the StateFulSet succcessfully such that the MySql has a persistent storage and not ephemeral.

Body:
I am trying to replace a deployment with StateFulSet having a persistent volume.

A quick summary:

The deployment was ran successfully for a web app having front end and backend (MySQL)

Then we deleted the deployment.

Wrote down the YAML file for Statefulset w.r.t backend.

applied the statefulset YAML.

However, the pod for MySQL does not come up and always goes into 'CrashLoopBackOff' state.

Request your help to understand the issue.

I am putting all the logs below - it is lengthy but hopefully it will help to better understand the entire scenario.

Original config:

~] $ kubectl get all
NAME                                  READY   STATUS    RESTARTS      AGE
pod/gowebapp-54f6cd5f64-6xl99         1/1     Running   0             73s
pod/gowebapp-54f6cd5f64-fn6sc         1/1     Running   3 (83s ago)   2m8s
pod/gowebapp-mysql-7c4ddfccdf-2x27f   1/1     Running   0             107s

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/gowebapp         ClusterIP   100.xx.xxx.xxx   <none>        8080/TCP   2m8s
service/gowebapp-mysql   ClusterIP   100.xx.xx.xx     <none>        3306/TCP   2m30s

NAME                             READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/gowebapp         2/2     2            2           2m20s
deployment.apps/gowebapp-mysql   1/1     1            1           2m30s

NAME                                        DESIRED   CURRENT   READY   AGE
replicaset.apps/gowebapp-54f6cd5f64         2         2         2       2m8s
replicaset.apps/gowebapp-5744cdff7d         0         0         0       2m20s
replicaset.apps/gowebapp-mysql-6b685888cd   0         0         0       2m30s
replicaset.apps/gowebapp-mysql-7c4ddfccdf   1         1         1       107s
[~] $

Aim of the exercise: To replace the deployment with StatefulSet having a persistent volume.

*Step 1: Delete the existing deployment for MySQL.*

[~] $ kubectl delete deployment gowebapp-mysql
deployment.apps "gowebapp-mysql" deleted

*Step 2: check the deployment no longer exists and hence the pod is terminated as well. *

[~] $ kubectl get all
NAME                                  READY   STATUS        RESTARTS        AGE
pod/gowebapp-54f6cd5f64-6xl99         1/1     Running       0               3m29s
pod/gowebapp-54f6cd5f64-fn6sc         1/1     Running       3 (3m39s ago)   4m24s
pod/gowebapp-mysql-7c4ddfccdf-2x27f   1/1     Terminating   0               4m3s

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/gowebapp         ClusterIP   100.xx.xxx.xxx   <none>        8080/TCP   4m24s
service/gowebapp-mysql   ClusterIP   100.xx.xx.xx     <none>        3306/TCP   4m46s

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/gowebapp   2/2     2            2           4m36s

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/gowebapp-54f6cd5f64   2         2         2       4m24s
replicaset.apps/gowebapp-5744cdff7d   0         0         0       4m36s
[~] $

*step 3: check the files in the working directory. Create the StatefulSet file.*

[~/gowebapp/gowebapp-mysql] $ ls -lrt
total 20
-rw-r--r-- 1 ABC!@# root 2619 Oct 24 20:24 gowebapp.sql
-rw-r--r-- 1 ABC!@# root   73 Jan  5 10:53 Dockerfile
-rw-r--r-- 1 ABC!@# root  238 Jan  5 10:54 gowebapp-mysql-service.yaml
-rw-r--r-- 1 ABC!@# root  631 Jan  5 10:54 gowebapp-mysql-deployment-lab02.yaml
-rw-r--r-- 1 ABC!@# root 1021 Jan  5 10:54 gowebapp-mysql-deployment.yaml
[~/gowebapp/gowebapp-mysql] $
[~/gowebapp/gowebapp-mysql] $ vi pv.yaml
[~/gowebapp/gowebapp-mysql] $
[~/gowebapp/gowebapp-mysql] $ cat pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv01
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteOnce
  hostPath:
    path: /var/pv/pv01

[~/gowebapp/gowebapp-mysql] $ cat gowebapp-mysql-sts.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: gowebapp-mysql
  labels:
    app: gowebapp-mysql
    tier: backend
spec:
  serviceName: gowebapp-mysql
  replicas: 1
  selector:
    matchLabels:
      app: gowebapp-mysql
      tier: backend
  template:
    metadata:
      labels:
        app: gowebapp-mysql
        tier: backend
    spec:
      containers:
      - name: gowebapp-mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: mypassword
        image: $REGISTRY_HOST/gowebapp-mysql:v1  *==> removing entire path on purpose*
        ports:
        - containerPort: 3306
        livenessProbe:
          tcpSocket:
            port: 3306
          initialDelaySeconds: 20
          periodSeconds: 5
          timeoutSeconds: 1
        readinessProbe:
          exec:
            command: ["mysql", "-uroot", "-XXXXXXXXXXXX", "-e", "use gowebapp; select count(*) from user"]
          initialDelaySeconds: 25
          periodSeconds: 10
          timeoutSeconds: 1
        volumeMounts:
        - name: mysql-pv
          mountPath: /var/lib/mysql
  volumeClaimTemplates:
  - metadata:
      name: mysql-pv
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 5Gi

*Step 4: apply the StatefulSet YAML file*

[~/gowebapp/gowebapp-mysql] $ kubectl apply -f gowebapp-mysql-sts.yaml
statefulset.apps/gowebapp-mysql created

*Step 5: check the configuration again. We observe the MySQL pod is in error. *

[~/gowebapp/gowebapp-mysql] $ kubectl get all
NAME                            READY   STATUS    RESTARTS      AGE
pod/gowebapp-54f6cd5f64-6xl99   1/1     Running   0             12m
pod/gowebapp-54f6cd5f64-fn6sc   1/1     Running   3 (12m ago)   13m
pod/gowebapp-mysql-0            0/1     Error     1 (2s ago)    19s

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/gowebapp         ClusterIP   100.xx.xxx.xxx   <none>        8080/TCP   13m
service/gowebapp-mysql   ClusterIP   100.xx.xx.xx     <none>        3306/TCP   13m

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/gowebapp   2/2     2            2           13m

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/gowebapp-54f6cd5f64   2         2         2       13m
replicaset.apps/gowebapp-5744cdff7d   0         0         0       13m

NAME                              READY   AGE
statefulset.apps/gowebapp-mysql   0/1     19s
[~/gowebapp/gowebapp-mysql] $

*Step 6: describe the MySQL pod which is in error to see the configuration and event logs.*

[~/gowebapp/gowebapp-mysql] $ kubectl describe pod gowebapp-mysql-0
Name:         gowebapp-mysql-0
Namespace:    eduk8s-labs-w19-s024
Priority:     0
Node:         ip-10-0-4-209.ec2.internal/10.0.4.209
Start Time:   Thu, 05 Jan 2023 11:07:26 +0000
Labels:       app=gowebapp-mysql
              controller-revision-hash=gowebapp-mysql-9bbb68b64
              statefulset.kubernetes.io/pod-name=gowebapp-mysql-0
              tier=backend
Annotations:  <none>
Status:       Running
IP:           100.x.x.x
IPs:
  IP:           100.x.x.x
Controlled By:  StatefulSet/gowebapp-mysql
Containers:
  gowebapp-mysql:
    Container ID:   containerd://464cfecbee1dccfb28e25adf1f12a2264ed44e30854b15ed25e5f69897e1aa15
    Image:          XXXXXXXXXXXXXXX/gowebapp-mysql:v1
    Image ID:       XXXXXXXXXXXXXXX/gowebapp-mysql@sha256:991935ad6c0c2b7e4ba7acdae920499d0a295ae29546277b42c0794efe9a95bf
    Port:           3306/TCP
    Host Port:      0/TCP
   ** State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated**
      Reason:       Error
      Exit Code:    141
      Started:      Thu, 05 Jan 2023 11:08:00 +0000
      Finished:     Thu, 05 Jan 2023 11:08:00 +0000
    Ready:          False
    Restart Count:  2
    Liveness:       tcp-socket :3306 delay=20s timeout=1s period=5s #success=1 #failure=3
    Readiness:      exec [mysql -uroot -XXXXXXX -e use gowebapp; select count(*) from user] delay=25s timeout=1s period=10s #success=1 #failure=3
    Environment:
      MYSQL_ROOT_PASSWORD:  XXXXXX
    Mounts:
      /var/lib/mysql from mysql-pv (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-kz5ds (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  mysql-pv:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mysql-pv-gowebapp-mysql-0
    ReadOnly:   false
  kube-api-access-kz5ds:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason                  Age                From                     Message
  ----     ------                  ----               ----                     -------
  **Warning  FailedScheduling        58s                default-scheduler        0/9 nodes are available: 9 pod has unbound immediate PersistentVolumeClaims.
  Warning  FailedScheduling        55s                default-scheduler        0/9 nodes are available: 9 pod has unbound immediate PersistentVolumeClaims.**
  Normal   Scheduled               53s                default-scheduler        Successfully assigned eduk8s-labs-w19-s024/gowebapp-mysql-0 to ip-10-0-4-209.ec2.internal
  Normal   SuccessfulAttachVolume  51s                attachdetach-controller  AttachVolume.Attach succeeded for volume "pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2"
  Normal   Pulling                 44s                kubelet                  Pulling image "XXXXXXXX/gowebapp-mysql:v1"
  Normal   Pulled                  42s                kubelet                  Successfully pulled image "XXXXXXXXXXXXXX/gowebapp-mysql:v1" in 1.33039215s
  Normal   Created                 19s (x3 over 42s)  kubelet                  Created container gowebapp-mysql
  Normal   Started                 19s (x3 over 42s)  kubelet                  Started container gowebapp-mysql
  Normal   Pulled                  19s (x2 over 41s)  kubelet                  Container image "XXXXXXXXXXXXXXXX/gowebapp-mysql:v1" already present on machine
  Warning  BackOff                 14s (x7 over 40s)  kubelet                  Back-off restarting failed container
[~/gowebapp/gowebapp-mysql] $

*step 7: check that PVC exists - which it does.*

[~/gowebapp/gowebapp-mysql] $ kubectl get pvc
NAME                        STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mysql-pv-gowebapp-mysql-0   Bound    pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2   5Gi        RWO            default        104s
[~/gowebapp/gowebapp-mysql] $
[~/gowebapp/gowebapp-mysql] $
[~/gowebapp/gowebapp-mysql] $ kubectl describe persistentvolumeclaims mysql-pv-gowebapp-mysql-0
Name:          mysql-pv-gowebapp-mysql-0
Namespace:     eduk8s-labs-w19-s024
StorageClass:  default
Status:        Bound
Volume:        pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2
Labels:        app=gowebapp-mysql
               tier=backend
Annotations:   pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
               volume.beta.kubernetes.io/storage-provisioner: ebs.csi.aws.com
               volume.kubernetes.io/storage-provisioner: ebs.csi.aws.com
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      5Gi
Access Modes:  RWO
VolumeMode:    Filesystem
Used By:       gowebapp-mysql-0
Events:
  Type    Reason                 Age                  From                                                                                Message
  ----    ------                 ----                 ----                                                                                -------
  Normal  ExternalProvisioning   117s (x2 over 117s)  persistentvolume-controller                                                               waiting for a volume to be created, either by external provisioner "ebs.csi.aws.com" or manually created by system administrator
  Normal  Provisioning           117s                 ebs.csi.aws.com_ebs-csi-controller-75ddf66bf8-fw4ww_f01348ce-0cd7-4464-a3c9-49c87925167d  External provisioner is provisioning volume for claim "eduk8s-labs-w19-s024/mysql-pv-gowebapp-mysql-0"
  Normal  ProvisioningSucceeded  114s                 ebs.csi.aws.com_ebs-csi-controller-75ddf66bf8-fw4ww_f01348ce-0cd7-4464-a3c9-49c87925167d  Successfully provisioned volume pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2
[~/gowebapp/gowebapp-mysql] $

*Step 8: again, we check the configuration to see that MySQL Pod is in 'CrashLoopBackOff'*

[~/gowebapp/gowebapp-mysql] $ kubectl get all
NAME                            READY   STATUS             RESTARTS      AGE
pod/gowebapp-54f6cd5f64-6xl99   1/1     Running            0             14m
pod/gowebapp-54f6cd5f64-fn6sc   1/1     Running            3 (14m ago)   15m
pod/gowebapp-mysql-0            0/1     CrashLoopBackOff   4 (18s ago)   2m18s

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/gowebapp         ClusterIP   100.xx.xxx.xxx   <none>        8080/TCP   15m
service/gowebapp-mysql   ClusterIP   100.xx.xx.xx     <none>        3306/TCP   15m

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/gowebapp   2/2     2            2           15m

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/gowebapp-54f6cd5f64   2         2         2       15m
replicaset.apps/gowebapp-5744cdff7d   0         0         0       15m

NAME                              READY   AGE
statefulset.apps/gowebapp-mysql   0/1     2m18s
[~/gowebapp/gowebapp-mysql] $

- **complete set of logs:**
note: removed the entire path for registry and purposefully replaced with XXXXXXXX.

[~/gowebapp/gowebapp-mysql] $ kubectl get events
LAST SEEN   TYPE      REASON                   OBJECT                                            MESSAGE
14m         Normal    Scheduled                pod/gowebapp-54f6cd5f64-6xl99                     Successfully assigned eduk8s-labs-w19-s024/gowebapp-54f6cd5f64-6xl99 to ip-10-0-0-47.ec2.internal
14m         Normal    Pulled                   pod/gowebapp-54f6cd5f64-6xl99                     Container image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1" already present on machine
14m         Normal    Created                  pod/gowebapp-54f6cd5f64-6xl99                     Created container gowebapp
14m         Normal    Started                  pod/gowebapp-54f6cd5f64-6xl99                     Started container gowebapp
15m         Normal    Scheduled                pod/gowebapp-54f6cd5f64-fn6sc                     Successfully assigned eduk8s-labs-w19-s024/gowebapp-54f6cd5f64-fn6sc to ip-10-0-4-38.ec2.internal
15m         Normal    Pulled                   pod/gowebapp-54f6cd5f64-fn6sc                     Container image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1" already present on machine
15m         Normal    Created                  pod/gowebapp-54f6cd5f64-fn6sc                     Created container gowebapp
15m         Normal    Started                  pod/gowebapp-54f6cd5f64-fn6sc                     Started container gowebapp
15m         Warning   Unhealthy                pod/gowebapp-54f6cd5f64-fn6sc                     Readiness probe failed: Get "http://100.96.2.240:8080/": dial tcp 100.96.2.240:8080: connect: connection refused
15m         Warning   Unhealthy                pod/gowebapp-54f6cd5f64-fn6sc                     Liveness probe failed: dial tcp 100.96.2.240:8080: connect: connection refused
15m         Normal    Killing                  pod/gowebapp-54f6cd5f64-fn6sc                     Container gowebapp failed liveness probe, will be restarted
15m         Normal    SuccessfulCreate         replicaset/gowebapp-54f6cd5f64                    Created pod: gowebapp-54f6cd5f64-fn6sc
14m         Normal    SuccessfulCreate         replicaset/gowebapp-54f6cd5f64                    Created pod: gowebapp-54f6cd5f64-6xl99
16m         Normal    Scheduled                pod/gowebapp-5744cdff7d-bfvdl                     Successfully assigned eduk8s-labs-w19-s024/gowebapp-5744cdff7d-bfvdl to ip-10-0-0-47.ec2.internal
16m         Normal    Pulling                  pod/gowebapp-5744cdff7d-bfvdl                     Pulling image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1"
15m         Normal    Pulled                   pod/gowebapp-5744cdff7d-bfvdl                     Successfully pulled image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1" in 2.293354548s
15m         Normal    Created                  pod/gowebapp-5744cdff7d-bfvdl                     Created container gowebapp
15m         Normal    Started                  pod/gowebapp-5744cdff7d-bfvdl                     Started container gowebapp
14m         Normal    Killing                  pod/gowebapp-5744cdff7d-bfvdl                     Stopping container gowebapp
16m         Normal    Scheduled                pod/gowebapp-5744cdff7d-ccc45                     Successfully assigned eduk8s-labs-w19-s024/gowebapp-5744cdff7d-ccc45 to ip-10-0-4-38.ec2.internal
16m         Normal    Pulling                  pod/gowebapp-5744cdff7d-ccc45                     Pulling image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1"
15m         Normal    Pulled                   pod/gowebapp-5744cdff7d-ccc45                     Successfully pulled image "XXXXXXXXXXXXXXXXXXXXX/gowebapp:v1" in 2.232486921s
15m         Normal    Created                  pod/gowebapp-5744cdff7d-ccc45                     Created container gowebapp
15m         Normal    Started                  pod/gowebapp-5744cdff7d-ccc45                     Started container gowebapp
14m         Normal    Killing                  pod/gowebapp-5744cdff7d-ccc45                     Stopping container gowebapp
16m         Normal    SuccessfulCreate         replicaset/gowebapp-5744cdff7d                    Created pod: gowebapp-5744cdff7d-ccc45
16m         Normal    SuccessfulCreate         replicaset/gowebapp-5744cdff7d                    Created pod: gowebapp-5744cdff7d-bfvdl
14m         Normal    SuccessfulDelete         replicaset/gowebapp-5744cdff7d                    Deleted pod: gowebapp-5744cdff7d-ccc45
14m         Normal    SuccessfulDelete         replicaset/gowebapp-5744cdff7d                    Deleted pod: gowebapp-5744cdff7d-bfvdl
*2m58s       Warning   FailedScheduling         pod/gowebapp-mysql-0                              0/9 nodes are available: 9 pod has unbound immediate PersistentVolumeClaims.
2m55s       Warning   FailedScheduling         pod/gowebapp-mysql-0                              0/9 nodes are available: 9 pod has unbound immediate PersistentVolumeClaims.
2m53s       Normal    Scheduled                pod/gowebapp-mysql-0                              Successfully assigned eduk8s-labs-w19-s024/gowebapp-mysql-0 to ip-10-0-4-209.ec2.internal
2m51s       Normal    SuccessfulAttachVolume   pod/gowebapp-mysql-0                              AttachVolume.Attach succeeded for volume "pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2"
2m44s       Normal    Pulling                  pod/gowebapp-mysql-0                              Pulling image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1"
2m42s       Normal    Pulled                   pod/gowebapp-mysql-0                              Successfully pulled image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1" in 1.33039215s
106s        Normal    Created                  pod/gowebapp-mysql-0                              Created container gowebapp-mysql
106s        Normal    Started                  pod/gowebapp-mysql-0                              Started container gowebapp-mysql
106s        Normal    Pulled                   pod/gowebapp-mysql-0                              Container image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1" already present on machine
88s         Warning   BackOff                  pod/gowebapp-mysql-0                              Back-off restarting failed container*
16m         Normal    Scheduled                pod/gowebapp-mysql-6b685888cd-vmbbt               Successfully assigned eduk8s-labs-w19-s024/gowebapp-mysql-6b685888cd-vmbbt to ip-10-0-2-110.ec2.internal
16m         Normal    Pulling                  pod/gowebapp-mysql-6b685888cd-vmbbt               Pulling image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1"
16m         Normal    Pulled                   pod/gowebapp-mysql-6b685888cd-vmbbt               Successfully pulled image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1" in 1.353941669s
16m         Normal    Created                  pod/gowebapp-mysql-6b685888cd-vmbbt               Created container gowebapp-mysql
16m         Normal    Started                  pod/gowebapp-mysql-6b685888cd-vmbbt               Started container gowebapp-mysql
16m         Normal    Killing                  pod/gowebapp-mysql-6b685888cd-vmbbt               Stopping container gowebapp-mysql
16m         Normal    SuccessfulCreate         replicaset/gowebapp-mysql-6b685888cd              Created pod: gowebapp-mysql-6b685888cd-vmbbt
16m         Normal    SuccessfulDelete         replicaset/gowebapp-mysql-6b685888cd              Deleted pod: gowebapp-mysql-6b685888cd-vmbbt
15m         Normal    Scheduled                pod/gowebapp-mysql-7c4ddfccdf-2x27f               Successfully assigned eduk8s-labs-w19-s024/gowebapp-mysql-7c4ddfccdf-2x27f to ip-10-0-2-110.ec2.internal
15m         Normal    Pulled                   pod/gowebapp-mysql-7c4ddfccdf-2x27f               Container image "XXXXXXXXXXXXXXXXXXXXX/gowebapp-mysql:v1" already present on machine
15m         Normal    Created                  pod/gowebapp-mysql-7c4ddfccdf-2x27f               Created container gowebapp-mysql
15m         Normal    Started                  pod/gowebapp-mysql-7c4ddfccdf-2x27f               Started container gowebapp-mysql
11m         Normal    Killing                  pod/gowebapp-mysql-7c4ddfccdf-2x27f               Stopping container gowebapp-mysql
11m         Warning   Unhealthy                pod/gowebapp-mysql-7c4ddfccdf-2x27f               Readiness probe failed: Warning: Using a password on the command line interface can be insecure....
15m         Normal    SuccessfulCreate         replicaset/gowebapp-mysql-7c4ddfccdf              Created pod: gowebapp-mysql-7c4ddfccdf-2x27f
16m         Normal    ScalingReplicaSet        deployment/gowebapp-mysql                         Scaled up replica set gowebapp-mysql-6b685888cd to 1
16m         Normal    ScalingReplicaSet        deployment/gowebapp-mysql                         Scaled down replica set gowebapp-mysql-6b685888cd to 0
15m         Normal    ScalingReplicaSet        deployment/gowebapp-mysql                         Scaled up replica set gowebapp-mysql-7c4ddfccdf to 1
2m59s       Normal    SuccessfulCreate         statefulset/gowebapp-mysql                        create Claim mysql-pv-gowebapp-mysql-0 Pod gowebapp-mysql-0 in StatefulSet gowebapp-mysql success
2m59s       Normal    SuccessfulCreate         statefulset/gowebapp-mysql                        create Pod gowebapp-mysql-0 in StatefulSet gowebapp-mysql successful
16m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled up replica set gowebapp-5744cdff7d to 2
15m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled up replica set gowebapp-54f6cd5f64 to 1
14m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled down replica set gowebapp-5744cdff7d to 1
14m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled up replica set gowebapp-54f6cd5f64 to 2
14m         Normal    ScalingReplicaSet        deployment/gowebapp                               Scaled down replica set gowebapp-5744cdff7d to 0
2m59s       Normal    ExternalProvisioning     persistentvolumeclaim/mysql-pv-gowebapp-mysql-0   waiting for a volume to be created, either by external provisioner "ebs.csi.aws.com" or manually created by system administrator
2m59s       Normal    Provisioning             persistentvolumeclaim/mysql-pv-gowebapp-mysql-0   External provisioner is provisioning volume for claim "eduk8s-labs-w19-s024/mysql-pv-gowebapp-mysql-0"
2m56s       Normal    ProvisioningSucceeded    persistentvolumeclaim/mysql-pv-gowebapp-mysql-0   Successfully provisioned volume pvc-6a8f5389-dd8a-4416-a704-8805fc6c8fc2
[

~/gowebapp/gowebapp-mysql] $

Tried to check the logs and other Stack overflow questions for similar error messages but did not help.

The expectation is to setup the StateFulSet succcessfully such that the MySql has a persistent storage and not ephemeral.


来源: stackexchange

问:
WebScraping with Java getInputStream(), redirect and umlauts
I have a url url = new URL("https://website.com/lang/npc="+id); and want to load the content with con.getInputStream() but that results in Server redirected too many  times (20).
This problem is because the website redirects me to a url with umlauts -> https://website.com/lang/npc=6/koboldgezücht

How to avoid this problem ?

ContentLicense: CC BY-SA 4.0


问:
How to extract QR code from ImageView in android
Suppose a PDF contains multiple QR codes. My task is to extract data from those QR codes without scanning them and just on it's click.

What I did?

I converted PDF pages into Images using PDFBox

Display those Images into ImageView

Convert them into Bitmap

Extract QR Code data from them using Zxing

Here If I extract data from Long PDF QR Data then it throws error i.e. JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception com.google.zxing.NotFoundException because the bitmap might be very big. So is there any possibility to extract just QR code from Image View and not any of the other content?

And if I extract data from Short PDF QR data then it works fine and extract data properly.

Code used to extract data is

```<code>var generatedQRCode =
                Bitmap.createBitmap(
                    binding.layoutMainDrawer.imageSign.width,
                    binding.layoutMainDrawer.imageSign.height,
                    Bitmap.Config.ARGB_8888
                )
            val canvas = Canvas(generatedQRCode)
            binding.layoutMainDrawer.imageSign.draw(canvas)
            val width = generatedQRCode.width
            val height = generatedQRCode.height
            val pixels = IntArray(width * height)
            generatedQRCode.getPixels(pixels, 0, width, 0, 0, width, height)
            generatedQRCode.recycle()
            generatedQRCode = null
            val source = RGBLuminanceSource(width, height, pixels)
            val binaryBitmap = BinaryBitmap(HybridBinarizer(source))
            val reader: Reader = MultiFormatReader()
            try {
                val result: Result? = reader.decode(binaryBitmap)
                Log.i("TextDecodedFromQrCode", result!!.text)
            } catch (e: NotFoundException) {
                e.printStackTrace()
            } catch (e: ChecksumException) {
                e.printStackTrace()
            } catch (e: FormatException) {
                e.printStackTrace()
            }
</code>```

Body:
Suppose a PDF contains multiple QR codes. My task is to extract data from those QR codes without scanning them and just on it's click.

What I did?

I converted PDF pages into Images using PDFBox

Display those Images into ImageView

Convert them into Bitmap

Extract QR Code data from them using Zxing

Here If I extract data from Long PDF QR Data then it throws error i.e. JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception com.google.zxing.NotFoundException because the bitmap might be very big. So is there any possibility to extract just QR code from Image View and not any of the other content?

And if I extract data from Short PDF QR data then it works fine and extract data properly.

Code used to extract data is

var generatedQRCode =
                Bitmap.createBitmap(
                    binding.layoutMainDrawer.imageSign.width,
                    binding.layoutMainDrawer.imageSign.height,
                    Bitmap.Config.ARGB_8888
                )
            val canvas = Canvas(generatedQRCode)
            binding.layoutMainDrawer.imageSign.draw(canvas)
            val width = generatedQRCode.width
            val height = generatedQRCode.height
            val pixels = IntArray(width * height)
            generatedQRCode.getPixels(pixels, 0, width, 0, 0, width, height)
            generatedQRCode.recycle()
            generatedQRCode = null
            val source = RGBLuminanceSource(width, height, pixels)
            val binaryBitmap = BinaryBitmap(HybridBinarizer(source))
            val reader: Reader = MultiFormatReader()
            try {
                val result: Result? = reader.decode(binaryBitmap)
                Log.i("TextDecodedFromQrCode", result!!.text)
            } catch (e: NotFoundException) {
                e.printStackTrace()
            } catch (e: ChecksumException) {
                e.printStackTrace()
            } catch (e: FormatException) {
                e.printStackTrace()
            }


问:
Publishing Blazor Server/Client to IIS through Web Deploy
I have a Blazor web-assembly core hosted app - so when debugging locally I have multiple startups selected on both the .Server and .Client when debugging, which when running then loads up the Server API swagger on https://localhost:5001 and the Client Blazor app on https://localhost:5005 and works fine.

The project is running .NET 7.0.

I am now looking to publish the app to a testing server through web deploy running IIS.

I have successfully deployed the files to the server using by publishing the .Server project to the testing server and I can see all files onthe server (including the client app resources) are successfully uploaded. By this I mean I can see all the api DLLs are there and the Client wwwroot folder is created, etc.

This has been published as release, net7.0 and self-contained.

However, when I then try to naivgate to the published URL, e.g. dev.mydomain.com I am getting a 404 error? Nagivating to either the :5001 or :5005 ports causes a time out as well.

From running dotnet --info on the server I can confirm that Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] is installed on the server.

From looking at this article Host and Deploy ASP.NET Core Blazor.

This references that in the Program.cs of the client app has the following code;

```<code>builder.Services.AddScoped(
    sp => new HttpClient
    {
        BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
    }
);
</code>```

Which if I copy and then run locally this passes the http://localhost:5005 of the client app and not the server API port. So currently I have;

```<code>ApiSettings apiSettings = builder.Configuration.GetSection("ApiSettings").Get<ApiSettings>();
builder.Services.AddScoped(
    sp => new HttpClient
    {
        BaseAddress = new Uri(apiSettings.Url + ":" + apiSettings.Port)
    }
);
</code>```

Which pulls from the appsettings.development.json and appsettings.production.json file in the wwwroot folder (I know not best practice - again I am open to solutions here).

I assume the app would run on the standard port 80 and then the API run on another specified port? Can anyone tell me where I am going wrong here please?

Body:
I have a Blazor web-assembly core hosted app - so when debugging locally I have multiple startups selected on both the .Server and .Client when debugging, which when running then loads up the Server API swagger on https://localhost:5001 and the Client Blazor app on https://localhost:5005 and works fine.

The project is running .NET 7.0.

I am now looking to publish the app to a testing server through web deploy running IIS.

I have successfully deployed the files to the server using by publishing the .Server project to the testing server and I can see all files onthe server (including the client app resources) are successfully uploaded. By this I mean I can see all the api DLLs are there and the Client wwwroot folder is created, etc.

This has been published as release, net7.0 and self-contained.

However, when I then try to naivgate to the published URL, e.g. dev.mydomain.com I am getting a 404 error? Nagivating to either the :5001 or :5005 ports causes a time out as well.

From running dotnet --info on the server I can confirm that Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] is installed on the server.

From looking at this article Host and Deploy ASP.NET Core Blazor.

This references that in the Program.cs of the client app has the following code;

builder.Services.AddScoped(
    sp => new HttpClient
    {
        BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
    }
);

Which if I copy and then run locally this passes the http://localhost:5005 of the client app and not the server API port. So currently I have;

ApiSettings apiSettings = builder.Configuration.GetSection("ApiSettings").Get<ApiSettings>();
builder.Services.AddScoped(
    sp => new HttpClient
    {
        BaseAddress = new Uri(apiSettings.Url + ":" + apiSettings.Port)
    }
);

Which pulls from the appsettings.development.json and appsettings.production.json file in the wwwroot folder (I know not best practice - again I am open to solutions here).

I assume the app would run on the standard port 80 and then the API run on another specified port? Can anyone tell me where I am going wrong here please?


问:
Undefined Reference to major, minor and makedev in libpython*.so file during Python-2.7.13 and Python-3.5.7 build
I am cross-compiling python-2.7.13 and python-3.5.7 from scratch using the following configuration command line options to the ./configure binary:

```<code>CONFIG_SITE=config.site ./configure \
    --host=arm-linux-gnueabi \
    --build=x86_64-pc-linux-gnu \
    CC=/toolchain/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc \
    RANLIB=/toolchain/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi/bin/arm-linux-gnueabi-ranlib \
    READELF=/toolchain/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi/bin/arm-linux-gnueabi-readelf \
    --enable-shared --enable-ipv6 --without-cxx-main --without-doc-strings --with-system-ffi --with-pydebug
</code>```

After the configuration is successful and the required Makefile is generated, when I am executing make to generate the python binary I am getting the following error:

```<code>/toolchain/arm/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc  -Xlinker -export-dynamic -o python \
                Modules/python.o \
                -L. -lpython2.7 -lpthread -ldl  -lpthread -lutil   -lm
./libpython2.7.so: undefined reference to `minor'
./libpython2.7.so: undefined reference to `major'
./libpython2.7.so: undefined reference to `makedev'
collect2: error: ld returned 1 exit status
make: *** [python] Error 1
</code>```

The toolchain which is being used for the cross-compilation is gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi downloaded from here: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads/8-2-2018-08

On further inspection of the /Modules/posixmodule.o executable using readelf, I found that the functions major, minor and makedev are in the UNDEF category, hence encountering the linking error.

```<code>readelf -s posixmodule.o | grep -i "major"
   409: 00004cb8    20 FUNC    LOCAL  DEFAULT    1 os_major_impl
   410: 00004ccc   124 FUNC    LOCAL  DEFAULT    1 os_major
  1288: 0000065c     1 OBJECT  LOCAL  DEFAULT    5 os_major__doc__
  1629: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND major

readelf -s posixmodule.o | grep -i "major"
   409: 00004cb8    20 FUNC    LOCAL  DEFAULT    1 os_major_impl
   410: 00004ccc   124 FUNC    LOCAL  DEFAULT    1 os_major
  1288: 0000065c     1 OBJECT  LOCAL  DEFAULT    5 os_major__doc__
  1629: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND major

readelf -s posixmodule.o | grep -i "minor"
   404: 00004c28    20 FUNC    LOCAL  DEFAULT    1 os_minor_impl
   405: 00004c3c   124 FUNC    LOCAL  DEFAULT    1 os_minor
  1287: 00000658     1 OBJECT  LOCAL  DEFAULT    5 os_minor__doc__
  1628: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND minor
</code>```

Could anyone help to resolve these errors?

Body:
I am cross-compiling python-2.7.13 and python-3.5.7 from scratch using the following configuration command line options to the ./configure binary:

CONFIG_SITE=config.site ./configure \
    --host=arm-linux-gnueabi \
    --build=x86_64-pc-linux-gnu \
    CC=/toolchain/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc \
    RANLIB=/toolchain/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi/bin/arm-linux-gnueabi-ranlib \
    READELF=/toolchain/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi/bin/arm-linux-gnueabi-readelf \
    --enable-shared --enable-ipv6 --without-cxx-main --without-doc-strings --with-system-ffi --with-pydebug

After the configuration is successful and the required Makefile is generated, when I am executing make to generate the python binary I am getting the following error:

/toolchain/arm/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc  -Xlinker -export-dynamic -o python \
                Modules/python.o \
                -L. -lpython2.7 -lpthread -ldl  -lpthread -lutil   -lm
./libpython2.7.so: undefined reference to `minor'
./libpython2.7.so: undefined reference to `major'
./libpython2.7.so: undefined reference to `makedev'
collect2: error: ld returned 1 exit status
make: *** [python] Error 1

The toolchain which is being used for the cross-compilation is gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabi downloaded from here: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads/8-2-2018-08

On further inspection of the /Modules/posixmodule.o executable using readelf, I found that the functions major, minor and makedev are in the UNDEF category, hence encountering the linking error.

readelf -s posixmodule.o | grep -i "major"
   409: 00004cb8    20 FUNC    LOCAL  DEFAULT    1 os_major_impl
   410: 00004ccc   124 FUNC    LOCAL  DEFAULT    1 os_major
  1288: 0000065c     1 OBJECT  LOCAL  DEFAULT    5 os_major__doc__
  1629: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND major

readelf -s posixmodule.o | grep -i "major"
   409: 00004cb8    20 FUNC    LOCAL  DEFAULT    1 os_major_impl
   410: 00004ccc   124 FUNC    LOCAL  DEFAULT    1 os_major
  1288: 0000065c     1 OBJECT  LOCAL  DEFAULT    5 os_major__doc__
  1629: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND major

readelf -s posixmodule.o | grep -i "minor"
   404: 00004c28    20 FUNC    LOCAL  DEFAULT    1 os_minor_impl
   405: 00004c3c   124 FUNC    LOCAL  DEFAULT    1 os_minor
  1287: 00000658     1 OBJECT  LOCAL  DEFAULT    5 os_minor__doc__
  1628: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND minor

Could anyone help to resolve these errors?


问:
Multidimensional array with affiliate tree
I'm working on a system with affiliate logic behind, with up to 3 levels in the structure.

I've got it working for 2 layers perfectly already. Here is the code I used for 2 layers. I'm using fat free Framework as a PHP Framework, shouldn't matter too much there though (think the code should be understandable without knowledge of the framework as well)...

PHP:

```<code>$firstLevel = $db->exec('SELECT * FROM users WHERE sponsorID=:sponsorID', array(':sponsorID' => $_SESSION['userid']));

$affiliateTree = [];

foreach ($firstLevel as $fl) {
    $secondLevel = $db->exec('SELECT * FROM users WHERE sponsorID=:sponsorID', array(':sponsorID' => $fl["ID"]));
    $affiliateTree[$fl["username"]] = [];
    foreach ($secondLevel as $sl) {
        $affiliateTree[$fl["username"]][] = $sl["username"];
    }
}

$f3->set('affiliateTree', $affiliateTree);
</code>```

HTML:

```<code><repeat group="{{ @affiliateTree }}" key="{{ @affKey }}" value="{{ @affVal }}">
  <li>
    <details open>
      <summary>{{@affKey}}</summary>
      <check if="{{@affVal}}">
        <true>
          <ul>
          <repeat group="{{@affVal}}" key={{@newAffKey}} value="{{@affiliate}}">
            <li>{{@affiliate}}</li>
          </repeat>
          </ul>
        </true>
      </check>
    </details>
  </li>

</repeat>
</code>```

That results in a list how I'd want it, something like that:

```<code>-paul
-olaf
   -jeanett
   -christine
-john
   -peter
   -tom
   -caroline
</code>```

My database table looks something like that (although would be willing to modify if needed):

```<code>ID | SponsorID | username

1  | NULL      | master
2  | 1         | paul
3  | 1         | olaf
4  | 3         | jeanettt
5  | 3         | christine
6  | 1         | john
7  | 6         | peter
8  | 6         | tom
9  | 6         | caroline
</code>```

Now I've tried to modify the code for the third layer, but failed in that.. So basically, if caroline would refer somebody as well, that should be displayed as well (so just an additional layer)...

How can I modify the code (or write new code) to get this done properly? What I've tried was the following:

PHP

```<code>foreach ($firstLevel as $fl) {
    $secondLevel = $db->exec('SELECT * FROM users WHERE sponsorID=:sponsorID', array(':sponsorID' => $fl["ID"]));
    $affiliateTree[$fl["username"]] = [];
    foreach ($secondLevel as $sl) {
        $thirdLevel = $db->exec('SELECT * FROM users WHERE sponsorID=:sponsorID', array(':sponsorID' => $sl["ID"]));
        $affiliateTree[$fl["username"]][] = [];
        foreach ($thirdLevel as $tl){
            $affiliateTree[$fl["username"]][$sl["username"]][] = $tl["username"];
        }
    }
}
</code>```

HTML:

```<code><repeat group="{{ @affiliateTree }}" key="{{ @affKey }}" value="{{ @affVal }}">
  <li>
    <details open>
      <summary>{{@affKey}}</summary>
      <check if="{{@affVal}}">
        <true>
          <ul>
          <repeat group="{{@affVal}}" key="{{@newAffKey}}" value="{{@affiliate}}">
            <li>
              <details open>
                <summary>{{@newAffKey}}</summary>
                <check if="{{@affiliate}}">
                  <true>
                    <ul>
                      <repeat group="{{@affiliate}}" value="{{@thirdLiner}}">
                        <li>{{@thirdLiner}}</li>
                      </repeat>
                    </ul>
                  </true>
                </check>
              </details>
            </li>
          </repeat>
          </ul>
        </true>
      </check>
    </details>
  </li>

</repeat>
</code>```

However, that didn't work at all.. Besides having some list elements with "0" in it, lots of users where missing for some reason...

How can I get this working? Any advise? I'm also down to completely changing code and database, if there's a more efficient way...

Body:
I'm working on a system with affiliate logic behind, with up to 3 levels in the structure.

I've got it working for 2 layers perfectly already. Here is the code I used for 2 layers. I'm using fat free Framework as a PHP Framework, shouldn't matter too much there though (think the code should be understandable without knowledge of the framework as well)...

PHP:

$firstLevel = $db->exec('SELECT * FROM users WHERE sponsorID=:sponsorID', array(':sponsorID' => $_SESSION['userid']));

$affiliateTree = [];

foreach ($firstLevel as $fl) {
    $secondLevel = $db->exec('SELECT * FROM users WHERE sponsorID=:sponsorID', array(':sponsorID' => $fl["ID"]));
    $affiliateTree[$fl["username"]] = [];
    foreach ($secondLevel as $sl) {
        $affiliateTree[$fl["username"]][] = $sl["username"];
    }
}

$f3->set('affiliateTree', $affiliateTree);

HTML:

<repeat group="{{ @affiliateTree }}" key="{{ @affKey }}" value="{{ @affVal }}">

      {{@affKey}}
      <check if="{{@affVal}}">
        <true>

          <repeat group="{{@affVal}}" key={{@newAffKey}} value="{{@affiliate}}">

{{@affiliate}}

          </repeat>

        </true>
      </check>

</repeat>

That results in a list how I'd want it, something like that:

-paul
-olaf
   -jeanett
   -christine
-john
   -peter
   -tom
   -caroline

My database table looks something like that (although would be willing to modify if needed):

ID | SponsorID | username

1  | NULL      | master
2  | 1         | paul
3  | 1         | olaf
4  | 3         | jeanettt
5  | 3         | christine
6  | 1         | john
7  | 6         | peter
8  | 6         | tom
9  | 6         | caroline

Now I've tried to modify the code for the third layer, but failed in that.. So basically, if caroline would refer somebody as well, that should be displayed as well (so just an additional layer)...

How can I modify the code (or write new code) to get this done properly? What I've tried was the following:

PHP

foreach ($firstLevel as $fl) {
    $secondLevel = $db->exec('SELECT * FROM users WHERE sponsorID=:sponsorID', array(':sponsorID' => $fl["ID"]));
    $affiliateTree[$fl["username"]] = [];
    foreach ($secondLevel as $sl) {
        $thirdLevel = $db->exec('SELECT * FROM users WHERE sponsorID=:sponsorID', array(':sponsorID' => $sl["ID"]));
        $affiliateTree[$fl["username"]][] = [];
        foreach ($thirdLevel as $tl){
            $affiliateTree[$fl["username"]][$sl["username"]][] = $tl["username"];
        }
    }
}

HTML:

<repeat group="{{ @affiliateTree }}" key="{{ @affKey }}" value="{{ @affVal }}">

      {{@affKey}}
      <check if="{{@affVal}}">
        <true>

          <repeat group="{{@affVal}}" key="{{@newAffKey}}" value="{{@affiliate}}">

                {{@newAffKey}}
                <check if="{{@affiliate}}">
                  <true>

                      <repeat group="{{@affiliate}}" value="{{@thirdLiner}}">

{{@thirdLiner}}

                      </repeat>

                  </true>
                </check>

          </repeat>

        </true>
      </check>

</repeat>

However, that didn't work at all.. Besides having some list elements with "0" in it, lots of users where missing for some reason...

How can I get this working? Any advise? I'm also down to completely changing code and database, if there's a more efficient way...


问:
Is it possible to fire event on buttons returned from PHP by API in angular 13?
I am using Angular Data-table. I returned edit and delete buttons from backend. The buttons are showing on frontend in UI but the click event or any other function is not working on them.
Can anyone guide me through this? Thanks in advance.

I tried all the things available on google but nothing work out.


问:
Error in Bias Correction of Precipitation Data using the Climate4R package
i was trying to correct the bias in NCEP reanalysis dataset with an observed precipitation data using Climate4R (an R package) in jupyter environment. The code as shown in the documentation did not run and gave an error massage which i can't resolve. I used the code as shown below;

```<code>cal <- biasCorrection(y = y, x = x.pr_native_grid,
                            precipitation = TRUE,
                            method = "eqm",
                            window = c(30, 15),
                            wet.threshold = 1,
                            cross.val = "kfold",
                            folds = list(1991:1995, 1996:2000, 2001:2005, 2006:2010, 2011:2015))
</code>```

this is the error i got

```<code>Error in if (any(years < min(all.years) | years > max(all.years))) {: missing value where TRUE/FALSE needed
</code>```

The traceback is;

```<code>1. biasCorrection(y = y, x = x.pr_native_grid, precipitation = TRUE,
 .     method = "eqm", window = c(30, 15), wet.threshold = 1, cross.val = "kfold",
 .     folds = list(1991:1995, 1996:2000, 2001:2005, 2006:2010,
 .         2011:2015))
2. lapply(1:length(years), function(i) {
 .     target.year <- years[[i]]
 .     rest.years <- setdiff(unlist(years), target.year)
 .     station <- FALSE
 .     if ("loc" %in% getDim(y))
 .         station <- TRUE
 .     yy <- redim(y, member = FALSE)
 .     yy <- if (method == "delta") {
 .         subsetGrid(yy, years = target.year, drop = FALSE)
 .     }
 .     else {
 .         subsetGrid(yy, years = rest.years, drop = FALSE)
 .     }
 .     if (isTRUE(station)) {
 .         yy$Data <- adrop(yy$Data, drop = 3)
 .         attr(yy$Data, "dimensions") <- c(setdiff(getDim(yy),
 .             c("lat", "lon")), "loc")
 .     }
 .     else {
 .         yy <- redim(yy, drop = TRUE)
 .     }
 .     newdata2 <- subsetGrid(x, years = target.year, drop = F)
 .     xx <- subsetGrid(x, years = rest.years, drop = F)
 .     message("Validation ", i, ", ", length(unique(years)) - i,
 .         " remaining")
 .     biasCorrectionXD(y = yy, x = xx, newdata = newdata2, precipitation = precipitation,
 .         method = method, window = window, scaling.type = scaling.type,
 .         fitdistr.args = fitdistr.args, pr.threshold = wet.threshold,
 .         n.quantiles = n.quantiles, extrapolation = extrapolation,
 .         theta = theta, join.members = join.members, detrend = detrend,
 .         isimip3.args = isimip3.args, return.raw = return.raw,
 .         interpGrid.args = interpGrid.args, parallel = parallel,
 .         max.ncores = max.ncores, ncores = ncores)
 . })
3. FUN(X[[i]], ...)
4. subsetGrid(yy, years = rest.years, drop = FALSE)
5. subsetYears(grid, years)
</code>```

I tried checking if there is missing values in the reanalysis dataset, but still gave the error. My observed dataset has no missing values.

Body:
i was trying to correct the bias in NCEP reanalysis dataset with an observed precipitation data using Climate4R (an R package) in jupyter environment. The code as shown in the documentation did not run and gave an error massage which i can't resolve. I used the code as shown below;

cal <- biasCorrection(y = y, x = x.pr_native_grid,
                            precipitation = TRUE,
                            method = "eqm",
                            window = c(30, 15),
                            wet.threshold = 1,
                            cross.val = "kfold",
                            folds = list(1991:1995, 1996:2000, 2001:2005, 2006:2010, 2011:2015))

this is the error i got

Error in if (any(years < min(all.years) | years > max(all.years))) {: missing value where TRUE/FALSE needed

The traceback is;

1. biasCorrection(y = y, x = x.pr_native_grid, precipitation = TRUE,
 .     method = "eqm", window = c(30, 15), wet.threshold = 1, cross.val = "kfold",
 .     folds = list(1991:1995, 1996:2000, 2001:2005, 2006:2010,
 .         2011:2015))
2. lapply(1:length(years), function(i) {
 .     target.year <- years[[i]]
 .     rest.years <- setdiff(unlist(years), target.year)
 .     station <- FALSE
 .     if ("loc" %in% getDim(y))
 .         station <- TRUE
 .     yy <- redim(y, member = FALSE)
 .     yy <- if (method == "delta") {
 .         subsetGrid(yy, years = target.year, drop = FALSE)
 .     }
 .     else {
 .         subsetGrid(yy, years = rest.years, drop = FALSE)
 .     }
 .     if (isTRUE(station)) {
 .         yy$Data <- adrop(yy$Data, drop = 3)
 .         attr(yy$Data, "dimensions") <- c(setdiff(getDim(yy),
 .             c("lat", "lon")), "loc")
 .     }
 .     else {
 .         yy <- redim(yy, drop = TRUE)
 .     }
 .     newdata2 <- subsetGrid(x, years = target.year, drop = F)
 .     xx <- subsetGrid(x, years = rest.years, drop = F)
 .     message("Validation ", i, ", ", length(unique(years)) - i,
 .         " remaining")
 .     biasCorrectionXD(y = yy, x = xx, newdata = newdata2, precipitation = precipitation,
 .         method = method, window = window, scaling.type = scaling.type,
 .         fitdistr.args = fitdistr.args, pr.threshold = wet.threshold,
 .         n.quantiles = n.quantiles, extrapolation = extrapolation,
 .         theta = theta, join.members = join.members, detrend = detrend,
 .         isimip3.args = isimip3.args, return.raw = return.raw,
 .         interpGrid.args = interpGrid.args, parallel = parallel,
 .         max.ncores = max.ncores, ncores = ncores)
 . })
3. FUN(X[[i]], ...)
4. subsetGrid(yy, years = rest.years, drop = FALSE)
5. subsetYears(grid, years)

I tried checking if there is missing values in the reanalysis dataset, but still gave the error. My observed dataset has no missing values.


问:
Not receiving push notification after firebase dependancy upgrade
we have raised our targetSDKVersion to 31 (android 12).
We end up getting following crash in firebase library. So we decided to upgrade our firebase version to latest to avoid it. We need help with properly migrating to new version. In earlier version we use FirebaseInstanceId to get token with projectNumber and register it with Notification service.

```<code>private static final String projectNumber = "335085002068";
> @Override
> protected Void doInBackground(Void... params) {
> String registrationID = null;
> try {
> FirebaseInstanceId.getInstance().deleteInstanceId();
> registrationID = FirebaseInstanceId.getInstance().getToken(projectNumber, FirebaseMessaging.INSTANCE_ID_SCOPE);
> catch (Exception exp) {
> Log.e(TAG, "firebase Instance ID exception", exp);
>     }
> _delegate.onCompletion(registrationID);
> return null;
> }
</code>```

FirebaseInstanceId is not available in newer versions, instead we tried to use FirebaseMessaging.getToken() and FirebaseInstallations but none of these APIs take projectNumber as attribute. Using FirebaseMessaging.getToken() and registering is not working.

```<code>> FirebaseMessaging.getInstance().getToken()
>     .addOnCompleteListener(new OnCompleteListener<String>() {
>         @Override
> public void onComplete(@NonNull Task<String> task) {
> if (!task.isSuccessful()) {
> Log.w(TAG, "Fetching FCM registration token failed", task.getException());
> return;
>           }
>
> Get new FCM registration token
> String token = task.getResult();
>
> Log and toast
> String msg = getString(R.string.msg_token_fmt, token);
> Log.d(TAG, msg);
> Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
>         }
>   });
</code>```

Can  anyone who encountered this in upgrading firebase please help us out here?
How to unlink projectNumber with our app with Notifcation service?

Upgraded to latest and try different solution from stackoverflow but nothing is woking
Looking for a solution or help

Body:
we have raised our targetSDKVersion to 31 (android 12).
We end up getting following crash in firebase library. So we decided to upgrade our firebase version to latest to avoid it. We need help with properly migrating to new version. In earlier version we use FirebaseInstanceId to get token with projectNumber and register it with Notification service.

private static final String projectNumber = "335085002068";
> @Override
> protected Void doInBackground(Void... params) {
> String registrationID = null;
> try {
> FirebaseInstanceId.getInstance().deleteInstanceId();
> registrationID = FirebaseInstanceId.getInstance().getToken(projectNumber, FirebaseMessaging.INSTANCE_ID_SCOPE);
> catch (Exception exp) {
> Log.e(TAG, "firebase Instance ID exception", exp);
>     }
> _delegate.onCompletion(registrationID);
> return null;
> }

FirebaseInstanceId is not available in newer versions, instead we tried to use FirebaseMessaging.getToken() and FirebaseInstallations but none of these APIs take projectNumber as attribute. Using FirebaseMessaging.getToken() and registering is not working.

> FirebaseMessaging.getInstance().getToken()
>     .addOnCompleteListener(new OnCompleteListener<String>() {
>         @Override
> public void onComplete(@NonNull Task<String> task) {
> if (!task.isSuccessful()) {
> Log.w(TAG, "Fetching FCM registration token failed", task.getException());
> return;
>           }
>
> Get new FCM registration token
> String token = task.getResult();
>
> Log and toast
> String msg = getString(R.string.msg_token_fmt, token);
> Log.d(TAG, msg);
> Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
>         }
>   });

Can  anyone who encountered this in upgrading firebase please help us out here?
How to unlink projectNumber with our app with Notifcation service?

Upgraded to latest and try different solution from stackoverflow but nothing is woking
Looking for a solution or help


问:
Teams toolkit Hello World Bot with SSO, show command not working
I am trying out the Hello World Bot with SSO sample which comes with the Teams toolkit.

"Show" command is not working as expected for me, getting a response as

There is an issue while trying to sign you in and retrieve your profile photo, please type "show" command to login and consent permissions again.

or

"We need to ask for additional permissions. You should only need to do this once for MyApplication" with two buttons "Cancel" and "Continue".

On clicking "Continue" no action is happening.

On debugging found that, tokenResponse.ssoToken is not getting set.

Any pointer on how to overcome it?


问:
How to pass two values for an option in Cobra?
I am writing a drop-in replacement for an existing tool.
This tool accepts command line options with two arguments:

```<code>--arg name value
</code>```

Is it possible to configure cobra in such way, that it would expect
two values for one argument?

(of course, it is possible to use = as a separator: --arg name=value etc, but as I said, it is not an option in my case, because I am working on a fully compatible drop-in replacement)

Body:
I am writing a drop-in replacement for an existing tool.
This tool accepts command line options with two arguments:

--arg name value

Is it possible to configure cobra in such way, that it would expect
two values for one argument?

(of course, it is possible to use = as a separator: --arg name=value etc, but as I said, it is not an option in my case, because I am working on a fully compatible drop-in replacement)


问:
Triangulated vtp File Plot Problem - matplotlib OpenFOAM vs Paraview Cut
maybe you can help me out with a right comment or hint for my problem.

Pretty easy, I would like to plot a 2D slice vtp file (OpenFOAM) via matplotlib as tricontourf plot.

1.) Creating the vtp slice by Paraview and saving as vtp file works like a charme

2.) Using the runtime vtp file, created by cuttingPlane - libsampling OpenFOAM creates a weird triangle order.

What am I missing?

Best,

```<code>def loadVTPFile(filename):
    import vtk
    from vtk.util.numpy_support import vtk_to_numpy
    from vtk.util import numpy_support as npvtk

    reader = vtk.vtkXMLPolyDataReader()
    reader.SetFileName(filename)
    reader.Update()
    data = reader.GetOutput()

    points = data.GetPoints()
    npts = points.GetNumberOfPoints()
    x = vtk_to_numpy(points.GetData())

    triangles=  vtk_to_numpy(data.GetPolys().GetData())
    ntri = triangles.size // 4  # number of cells
    tri = np.take(triangles,[n for n in range(triangles.size) if n%4 != 0]).reshape(ntri,3)

    n_arrays = reader.GetNumberOfPointArrays()
    for i in range(n_arrays):
        print(reader.GetPointArrayName(i))

    X = vtk_to_numpy(points.GetData())
    x=X[:,0]
    y=X[:,1]
    z=X[:,2]

    # Define the velocity components U=(u,v,w)
    U = vtk_to_numpy(data.GetPointData().GetArray('UMean'))
    u = U[:,0]
    v = U[:,1]
    w = U[:,2]
    magU=np.sqrt(u**2+v**2+w**2)

    p = vtk_to_numpy(data.GetPointData().GetArray('pMean'))
    Ma = vtk_to_numpy(data.GetPointData().GetArray('MaMean'))
    rho = vtk_to_numpy(data.GetPointData().GetArray('rhoMean'))

    return x,y,z,u,v,w,magU,p,Ma,rho,tri
</code>```

1st: Paraview vtp slice via matplotlib:
Paraview vtp slice via matplotlib

2nd image OpenFOAM cut via libsampling
2nd image OpenFOAM cut via libsampling

Thanks for your help

OpenFOAM vtp slice export:
cellPoint, triangulated true/false, interpolated true/false and so on...

Body:
maybe you can help me out with a right comment or hint for my problem.

Pretty easy, I would like to plot a 2D slice vtp file (OpenFOAM) via matplotlib as tricontourf plot.

1.) Creating the vtp slice by Paraview and saving as vtp file works like a charme

2.) Using the runtime vtp file, created by cuttingPlane - libsampling OpenFOAM creates a weird triangle order.

What am I missing?

Best,

def loadVTPFile(filename):
    import vtk
    from vtk.util.numpy_support import vtk_to_numpy
    from vtk.util import numpy_support as npvtk

    reader = vtk.vtkXMLPolyDataReader()
    reader.SetFileName(filename)
    reader.Update()
    data = reader.GetOutput()

    points = data.GetPoints()
    npts = points.GetNumberOfPoints()
    x = vtk_to_numpy(points.GetData())

    triangles=  vtk_to_numpy(data.GetPolys().GetData())
    ntri = triangles.size // 4  # number of cells
    tri = np.take(triangles,[n for n in range(triangles.size) if n%4 != 0]).reshape(ntri,3)

    n_arrays = reader.GetNumberOfPointArrays()
    for i in range(n_arrays):
        print(reader.GetPointArrayName(i))

    X = vtk_to_numpy(points.GetData())
    x=X[:,0]
    y=X[:,1]
    z=X[:,2]

    # Define the velocity components U=(u,v,w)
    U = vtk_to_numpy(data.GetPointData().GetArray('UMean'))
    u = U[:,0]
    v = U[:,1]
    w = U[:,2]
    magU=np.sqrt(u**2+v**2+w**2)

    p = vtk_to_numpy(data.GetPointData().GetArray('pMean'))
    Ma = vtk_to_numpy(data.GetPointData().GetArray('MaMean'))
    rho = vtk_to_numpy(data.GetPointData().GetArray('rhoMean'))

    return x,y,z,u,v,w,magU,p,Ma,rho,tri

1st: Paraview vtp slice via matplotlib:
Paraview vtp slice via matplotlib

2nd image OpenFOAM cut via libsampling
2nd image OpenFOAM cut via libsampling

Thanks for your help

OpenFOAM vtp slice export:
cellPoint, triangulated true/false, interpolated true/false and so on...


问:
Migrate rails application using ar-octopus gem to Rails v6.x.x
Did Rails Dev, migration rails app using ar-octopus to rails version 6/7.

As I see there are no updates regarding the rails v6 in ar-actopus gem, did any tried to upgrade on own.

Thanks in Advance.


问:
C# ListView Select Multiple Items Fires ItemSelectionChanged and SelectedIndexChanged multiple times
I created a list view where I added rows of data coming from the database.  Imagine there are 200 records in the list view, user selects the first row, then hold shift and click the last row.  This will practically select all 200 rows.  My problem is ItemSelectionChanged  and SelectedIndexChanged  are called 200 times.  I just want my logic to run when everything is finished with selection process.  I can't find solution anywhere so far.</p>


问:
How to change the colour of a ScrollView's scrollbar when the user has set dark mode on in React Native Android?
Long story short, if I use a <ScrollView> element while my decide doesn't have dark mode on, the scrollbar is dark grey-ish, however, if the user has dark mode on, it's lighter colour and blends with my app's background.

I was wondering if there's a simple way to change the colour of a ScrollView's scrollbar when dark mode in on in Android React Native?


问:
CDKworkshop: ImportError: No module named aws_cdk
I'm following the CDKworkshop.com. All good until the Advanced topic: Testing constructs -> Assertion tests. When I execute the pytest command it gives the error:

```<code>tests/unit/test_cdk_workshop.py:1: in <module>
from aws_cdk import (
E   ImportError: No module named aws_cdk
</code>```

I Followed all the steps in the workshop.

Activated venv

```<code>source .venv/bin/activate
</code>```

installed the requirements.txt

```<code>aws-cdk-lib==2.37.0
constructs>=10.0.0,<11.0.0
cdk-dynamo-table-view==0.2.0
</code>```

installed the requirements-dev.txt

```<code>pytest==6.2.5
</code>```

Expected output from running pytest command:

```<code>
$ pytest
===============session starts =======================================
platform linux -- Python 3.9.6, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: ...
collected 1 item

tests/unit/test_cdk_workshop.py .                                                                                [100%]

======================================================================
</code>```

Body:
I'm following the CDKworkshop.com. All good until the Advanced topic: Testing constructs -> Assertion tests. When I execute the pytest command it gives the error:

tests/unit/test_cdk_workshop.py:1: in <module>
from aws_cdk import (
E   ImportError: No module named aws_cdk

I Followed all the steps in the workshop.

Activated venv

source .venv/bin/activate

installed the requirements.txt

aws-cdk-lib==2.37.0
constructs>=10.0.0,<11.0.0
cdk-dynamo-table-view==0.2.0

installed the requirements-dev.txt

pytest==6.2.5

Expected output from running pytest command:

$ pytest
===============session starts =======================================
platform linux -- Python 3.9.6, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: ...
collected 1 item

tests/unit/test_cdk_workshop.py .                                                                                [100%]

======================================================================


问:
What is wrong behind my ALB on AWS that I get a 404 error (random)?
I have set an AWS application load balancer to redirect to IIS (ec2).
There will be more ec2 afterwards. For now, for testing purpose, I only redirect to this VM.
I also set an A record on Route53 pointing to the AWS balancer url.

Problem is that some times I reach the target, and sometimes I dont (with 404 error). Random.

For example, I visit:

http://labcac.netcontent.com.ar:8080/assets/css/bootstrap/bootstrap.min.css

It goes well. Once or twice. Third time, I get 404 error page.

Instead, If I use the public IP of IIS (instead of the Route53 record pointing to the ALB) it always works ok.

What am I doing wrong?

Listener


问:
Python plotly multi index/pivot dataframe to line chart
I have the following Data and I am trying to create a line chart (in a dashboard) out of it. I want it to be filterable by the column "JR" (like in a dropdown menu or sth.) and it should display the count of JR´s by calender week.

Example for my data:

```<code>NAME  JR ISO_WEEK
Alex  1  28
Ryan  3  28
Maria 1  29
Lisa  5  37
Jean  2  29
</code>```

I am not quite sure how to aggregate the data, to create the visualisation I mentioned above.
I already tried it as a Multi-Index Dataframe or as an pivot table, but couldn´t figure out an solution. Thanks a lot for your help :)

Body:
I have the following Data and I am trying to create a line chart (in a dashboard) out of it. I want it to be filterable by the column "JR" (like in a dropdown menu or sth.) and it should display the count of JR´s by calender week.

Example for my data:

NAME  JR ISO_WEEK
Alex  1  28
Ryan  3  28
Maria 1  29
Lisa  5  37
Jean  2  29

I am not quite sure how to aggregate the data, to create the visualisation I mentioned above.
I already tried it as a Multi-Index Dataframe or as an pivot table, but couldn´t figure out an solution. Thanks a lot for your help :)


问:
Clustering with lat longs and other constaints
I have data with different localities with their Lat Longs and their respective populations.
I have to cluster these localities in a way that max radius of a cluster must be 7 kms and minimum population of a cluster can be 5K.
Can somebody please help me with the python code. Or any ideas as how can I proceed with this.</p>


问:
Unable to save file in VS code
I have Docker env setup and I have just installed some new files related to playwright testing and there is tests folder and other configurations files when I save I got following error in vs code:

And below is directory and I have another tests folder under frontend like: /tests/frontend/tests

How I can save these folder and files?

Title: Unable to save file in VS code


问:
How can extract CHIRPS data value and their coordinates in CSV, Excel, or txt format files using python code?
How can I extract CHIRPS data value in a file (CSV, xlsx, or txt) along with their coordinates using python code?

However, many cloud base processing platforms like "Climate engine" provides the facility to extract values (daily, monthly, or yearly rainfall)in a CSV or Excel file but the problem is that the data do not have coordinates (LAT and Long) for the specified values.
Thus, we can not visualize and conduct any location-based analyzes in any GIS software.

I tried to extract rainfall data from the CHIRPS dataset using code in jupyter notebook, but I could not succeed to extract the values along with their coordinates in the same file.