troubleshooting in k8s

concepts

concepts
1. Application Failure
2. Control Plane Failure 
3. Worker Node Failure
4. Network failure

fix_app

fix_app
root@controlplane:~# kubectl get all -n alpha
NAME                                READY   STATUS    RESTARTS   AGE
pod/mysql                           1/1     Running   0          2m14s
pod/webapp-mysql-75dfdf859f-g6c69   1/1     Running   0          2m13s

NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/mysql         ClusterIP   10.101.228.242   <none>        3306/TCP         2m14s
service/web-service   NodePort    10.105.190.144   <none>        8080:30081/TCP   2m13s

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/webapp-mysql   1/1     1            1           2m13s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/webapp-mysql-75dfdf859f   1         1         1       2m13s
root@controlplane:~#


root@controlplane:~# kubectl get svc -n alpha
NAME          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
mysql         ClusterIP   10.101.228.242   <none>        3306/TCP         5m11s
web-service   NodePort    10.105.190.144   <none>        8080:30081/TCP   5m10s
root@controlplane:~# kubectl edit svc mysql -n alpha
A copy of your changes has been stored to "/tmp/kubectl-edit-5wbl3.yaml"
error: At least one of apiVersion, kind and name was changed
root@controlplane:~#
root@controlplane:~# kubectl delete svc mysql -n alpha
service "mysql" deleted
root@controlplane:~# kubectl apply -f /tmp/kubectl-edit-5wbl3.yaml -n alpha
service/mysql-service created
root@controlplane:~# kubectl get svc -n alpha
NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
mysql-service   ClusterIP   10.101.228.242   <none>        3306/TCP         9s
web-service     NodePort    10.105.190.144   <none>        8080:30081/TCP   7m18s
root@controlplane:~# 



root@controlplane:~# kubectl get all -n beta
NAME                                READY   STATUS    RESTARTS   AGE
pod/mysql                           1/1     Running   0          2m21s
pod/webapp-mysql-75dfdf859f-cnjvc   1/1     Running   0          2m21s

NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/mysql-service   ClusterIP   10.105.137.114   <none>        3306/TCP         2m21s
service/web-service     NodePort    10.98.182.217    <none>        8080:30081/TCP   2m20s

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/webapp-mysql   1/1     1            1           2m21s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/webapp-mysql-75dfdf859f   1         1         1       2m22s
root@controlplane:~# 




root@controlplane:~# kubectl get all -n delta
NAME                                READY   STATUS    RESTARTS   AGE
pod/mysql                           1/1     Running   0          32s
pod/webapp-mysql-67cfc57cbc-s2t4r   1/1     Running   0          32s

NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/mysql-service   ClusterIP   10.105.81.242    <none>        3306/TCP         32s
service/web-service     NodePort    10.103.208.202   <none>        8080:30081/TCP   32s

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/webapp-mysql   1/1     1            1           32s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/webapp-mysql-67cfc57cbc   1         1         1       32s
root@controlplane:~# 



root@controlplane:~# kubectl get all -n epsilon
NAME                                READY   STATUS    RESTARTS   AGE
pod/mysql                           1/1     Running   0          3m32s
pod/webapp-mysql-75dfdf859f-8zfkr   1/1     Running   0          2m14s

NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/mysql-service   ClusterIP   10.101.73.160   <none>        3306/TCP         3m33s
service/web-service     NodePort    10.111.193.14   <none>        8080:30081/TCP   3m32s

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/webapp-mysql   1/1     1            1           3m32s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/webapp-mysql-67cfc57cbc   0         0         0       3m32s
replicaset.apps/webapp-mysql-75dfdf859f   1         1         1       2m14s
root@controlplane:~# kubectl edit pod/webapp-mysql-75dfdf859f-8zfkr -n epsilon
Edit cancelled, no changes made.
root@controlplane:~# kubectl edit pod/mysql -n epsilon
error: pods "mysql" is invalid
A copy of your changes has been stored to "/tmp/kubectl-edit-8brmz.yaml"
error: Edit cancelled, no valid changes were saved.
root@controlplane:~# kubectl delete pod mysql -n epsilon
pod "mysql" deleted
kubectl apply -f /tmp/kubectl-edit-8brmz.yaml -n epsilon



root@controlplane:~# kubectl get all -n zeta
NAME                                READY   STATUS    RESTARTS   AGE
pod/mysql                           1/1     Running   0          26s
pod/webapp-mysql-67cfc57cbc-mbcsj   1/1     Running   0          26s

NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/mysql-service   ClusterIP   10.103.164.30   <none>        3306/TCP         27s
service/web-service     NodePort    10.102.1.35     <none>        8080:30088/TCP   26s

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/webapp-mysql   1/1     1            1           26s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/webapp-mysql-67cfc57cbc   1         1         1       26s
root@controlplane:~# kubectl edit service/web-service -n zeta
Edit cancelled, no changes made.
root@controlplane:~# kubectl edit service/mysql-service -n zeta
Edit cancelled, no changes made.
root@controlplane:~# kubectl edit pod/mysql -n zeta
A copy of your changes has been stored to "/tmp/kubectl-edit-b9kox.yaml"
error: Edit cancelled, no valid changes were saved.
root@controlplane:~# kubectl delete pod mysql -n zeta
pod "mysql" deleted
root@controlplane:~# 
root@controlplane:~# kubectl apply -f /tmp/kubectl-edit-b9kox.yaml -n zeta
pod/mysql created
root@controlplane:~#

fix_controlplane

fix_controlplane
root@controlplane:~# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS      MESSAGE                                                                                       ERROR
controller-manager   Unhealthy   Get "http://127.0.0.1:10252/healthz": dial tcp 127.0.0.1:10252: connect: connection refused   
scheduler            Unhealthy   Get "http://127.0.0.1:10251/healthz": dial tcp 127.0.0.1:10251: connect: connection refused   
etcd-0               Healthy     {"health":"true"}                                                                             
root@controlplane:~# kubectl get pods -n kube-system
NAME                                   READY   STATUS             RESTARTS   AGE
coredns-74ff55c5b-dmn7d                1/1     Running            0          11m
coredns-74ff55c5b-kcj74                1/1     Running            0          11m
etcd-controlplane                      1/1     Running            0          11m
kube-apiserver-controlplane            1/1     Running            0          11m
kube-controller-manager-controlplane   1/1     Running            0          11m
kube-flannel-ds-nvjfr                  1/1     Running            0          11m
kube-proxy-wsgdk                       1/1     Running            0          11m
kube-scheduler-controlplane            0/1     CrashLoopBackOff   3          89s
root@controlplane:~# 


root@controlplane:~# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS      MESSAGE                                                                                       ERROR
controller-manager   Unhealthy   Get "http://127.0.0.1:10252/healthz": dial tcp 127.0.0.1:10252: connect: connection refused   
scheduler            Unhealthy   Get "http://127.0.0.1:10251/healthz": dial tcp 127.0.0.1:10251: connect: connection refused   
etcd-0               Healthy     {"health":"true"}                                                                             
root@controlplane:~# kubectl get pods -n kube-system
NAME                                   READY   STATUS             RESTARTS   AGE
coredns-74ff55c5b-dmn7d                1/1     Running            0          11m
coredns-74ff55c5b-kcj74                1/1     Running            0          11m
etcd-controlplane                      1/1     Running            0          11m
kube-apiserver-controlplane            1/1     Running            0          11m
kube-controller-manager-controlplane   1/1     Running            0          11m
kube-flannel-ds-nvjfr                  1/1     Running            0          11m
kube-proxy-wsgdk                       1/1     Running            0          11m
kube-scheduler-controlplane            0/1     CrashLoopBackOff   3          89s
root@controlplane:~# 



root@controlplane:/etc/kubernetes/manifests# kubectl get all 
NAME                       READY   STATUS    RESTARTS   AGE
pod/app-586bddbc54-djlqq   1/1     Running   0          38s
pod/app-586bddbc54-gkknn   1/1     Running   0          12m

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   23m

NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/app   2/2     2            2           12m

NAME                             DESIRED   CURRENT   READY   AGE
replicaset.apps/app-586bddbc54   2         2         2       12m
root@controlplane:/etc/kubernetes/manifests# 

fix_nodefailure

fix_nodefailure
root@controlplane:~# kubectl get nodes -o wide
NAME           STATUS   ROLES                  AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
controlplane   Ready    control-plane,master   20m   v1.20.0   10.53.130.3   <none>        Ubuntu 18.04.5 LTS   5.4.0-1052-gcp   docker://19.3.0
node01         Ready    <none>                 19m   v1.20.0   10.53.130.6   <none>        Ubuntu 18.04.5 LTS   5.4.0-1052-gcp   docker://19.3.0
root@controlplane:~# 


root@controlplane:~# kubectl get nodes
NAME           STATUS     ROLES                  AGE   VERSION
controlplane   Ready      control-plane,master   21m   v1.20.0
node01         NotReady   <none>                 20m   v1.20.0
root@controlplane:~# 



root@node01:~# cd /etc/systemd/system/kubelet.service.d/
root@node01:/etc/systemd/system/kubelet.service.d# pwd
/etc/systemd/system/kubelet.service.d
root@node01:/etc/systemd/system/kubelet.service.d# cat 10-kubeadm.conf 
# Note: This dropin only works with kubeadm and kubelet v1.11+
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/default/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
root@node01:/etc/systemd/system/kubelet.service.d# 


root@controlplane:~# kubectl get nodes
NAME           STATUS   ROLES                  AGE   VERSION
controlplane   Ready    control-plane,master   27m   v1.20.0
node01         Ready    <none>                 27m   v1.20.0
root@controlplane:~# 


root@node01:/var/lib/kubelet# service kubelet status
● kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/kubelet.service.d
           └─10-kubeadm.conf
   Active: active (running) since Wed 2021-09-29 00:18:25 UTC; 17s ago
     Docs: https://kubernetes.io/docs/home/
 Main PID: 12506 (kubelet)
    Tasks: 35 (limit: 5529)
   CGroup: /system.slice/kubelet.service
           └─12506 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --k

Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.690184   12506 topology_manager.go:187] [topolo
Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.789994   12506 reconciler.go:224] operationExec
Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.790057   12506 reconciler.go:224] operationExec
Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.790076   12506 reconciler.go:224] operationExec
Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.790100   12506 reconciler.go:224] operationExec
Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.790117   12506 reconciler.go:224] operationExec
Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.790133   12506 reconciler.go:224] operationExec
Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.790206   12506 reconciler.go:224] operationExec
Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.790322   12506 reconciler.go:224] operationExec
Sep 29 00:18:27 node01 kubelet[12506]: I0929 00:18:27.790363   12506 reconciler.go:157] Reconciler: s
root@node01:/var/lib/kubelet#



root@controlplane:~# kubectl get nodes
NAME           STATUS     ROLES                  AGE   VERSION
controlplane   Ready      control-plane,master   31m   v1.20.0
node01         NotReady   <none>                 30m   v1.20.0
root@controlplane:~# 

fix kubelet service.

root@controlplane:~# kubectl get nodes
NAME           STATUS   ROLES                  AGE   VERSION
controlplane   Ready    control-plane,master   38m   v1.20.0
node01         Ready    <none>                 38m   v1.20.0
root@controlplane:~# 


always use "--no-pager" option with journalctl to see full readable logs

root@node01:/etc/kubernetes/pki# journalctl -u kubelet --no-pager -f
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.152194   16383 eviction_manager.go:260] eviction manager: failed to get summary stats: failed to get node info: node "node01" not found
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.162151   16383 kubelet.go:2240] node "node01" not found
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.262354   16383 kubelet.go:2240] node "node01" not found
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.362600   16383 kubelet.go:2240] node "node01" not found
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.462875   16383 kubelet.go:2240] node "node01" not found
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.563084   16383 kubelet.go:2240] node "node01" not found
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.663298   16383 kubelet.go:2240] node "node01" not found
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.763502   16383 kubelet.go:2240] node "node01" not found
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.863697   16383 kubelet.go:2240] node "node01" not found
Sep 29 00:35:56 node01 kubelet[16383]: I0929 00:35:56.907813   16383 kubelet_node_status.go:71] Attempting to register node node01
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.909407   16383 kubelet_node_status.go:93] Unable to register node "node01" with API server: Post "https://controlplane:6553/api/v1/nodes": dial tcp 10.53.130.2:6553: connect: connection refused
Sep 29 00:35:56 node01 kubelet[16383]: E0929 00:35:56.963833   16383 kubelet.go:2240] node "node01" not found
Sep 29 00:35:57 node01 kubelet[16383]: E0929 00:35:57.064046   16383 kubelet.go:2240] node "node01" not found

kube-proxy

kube-proxy
Network Plugin in Kubernetes:
-------------------------------------------->

Kubernetes uses CNI plugins to setup network. The kubelet is responsible for executing plugins as we mention the following parameters in kubelet configuration.

– cni-bin-dir:  Kubelet probes this directory for plugins on startup

– network-plugin: The network plugin to use from cni-bin-dir. It must match the name reported by a plugin probed from the plugin directory.


DNS:
---------->

If you find CoreDNS pods in pending state first check network plugin is installed.

2. coredns pods have CrashLoopBackOff or Error state

If you have nodes that are running SELinux with an older version of Docker 
you might experience a scenario where the coredns pods are not starting. \
To solve that you can try one of the following options:

a)Upgrade to a newer version of Docker.

b)Disable SELinux.


c)Modify the coredns deployment to set "allowPrivilegeEscalation to true":

kubectl -n kube-system get deployment coredns -o yaml | \
  sed 's/allowPrivilegeEscalation: false/allowPrivilegeEscalation: true/g' | \
  kubectl apply -f -

kubeproxy-failure

kubeproxy-failure
root@controlplane:/# kubectl get all -n triton
NAME                                READY   STATUS              RESTARTS   AGE
pod/mysql                           0/1     ContainerCreating   0          44s
pod/webapp-mysql-54db464f4f-jfg42   0/1     ContainerCreating   0          43s

NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/mysql         ClusterIP   10.108.89.216    <none>        3306/TCP         44s
service/web-service   NodePort    10.101.145.126   <none>        8080:30081/TCP   43s

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/webapp-mysql   0/1     1            0           43s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/webapp-mysql-54db464f4f   1         1         0       43s
root@controlplane:/# 

root@controlplane:/etc/kubernetes/manifests# kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
serviceaccount/weave-net created
clusterrole.rbac.authorization.k8s.io/weave-net created
clusterrolebinding.rbac.authorization.k8s.io/weave-net created
role.rbac.authorization.k8s.io/weave-net created
rolebinding.rbac.authorization.k8s.io/weave-net created
daemonset.apps/weave-net created
root@controlplane:/etc/kubernetes/manifests# 


root@controlplane:/etc/kubernetes/manifests# kubectl -n kube-system logs kube-proxy-cklbr
F0929 01:08:39.832255       1 server.go:490] failed complete: open /var/lib/kube-proxy/configuration.conf: no such file or directory
root@controlplane:/etc/kubernetes/manifests# kubectl get cm -n kube-system
NAME                                 DATA   AGE
coredns                              1      66m
extension-apiserver-authentication   6      66m
kube-proxy                           2      66m
kube-root-ca.crt                     1      66m
kubeadm-config                       2      66m
kubelet-config-1.20                  1      66m
weave-net                            0      66m
root@controlplane:/etc/kubernetes/manifests# 

json_jq

json_jq
MacBook-Pro:11.Troubleshooting bharathdasaraju$ cat test.json | jq .[0]
"hi"
MacBook-Pro:11.Troubleshooting bharathdasaraju$ cat test.json | jq .[]
"hi"
"hello"
"test"
MacBook-Pro:11.Troubleshooting bharathdasaraju$ cat test.json | jq .[0,1,2]
"hi"
"hello"
"test"
MacBook-Pro:11.Troubleshooting bharathdasaraju$ cat test.json | jq .[0,2]
"hi"
"test"
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 


---------------------------------------------------------------------------------------------------------->

MacBook-Pro:11.Troubleshooting bharathdasaraju$ cat test2.json | jq .vehicles
{
  "car": {
    "color": "blue",
    "price": "$20,000"
  },
  "bus": {
    "color": "white",
    "price": "$120,000"
  }
}
MacBook-Pro:11.Troubleshooting bharathdasaraju$ cat test2.json | jq .vehicles.car
{
  "color": "blue",
  "price": "$20,000"
}
MacBook-Pro:11.Troubleshooting bharathdasaraju$ cat test2.json | jq .vehicles.car.price
"$20,000"
MacBook-Pro:11.Troubleshooting bharathdasaraju$ cat test2.json | jq .vehicles.bus.price
"$120,000"
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 

json_path

json_path
{
  "property1": "value1",
  "property2": "value2"
}

$.property1

--------------------------------->

{
  "car": {
    "color": "blue",
    "price": "$20,000"
  },
  "bus": {
    "color": "white",
    "price": "$120,000"
  }
}

$.bus
$.bus.price

---------------------------------------->

{
  "vehicles": {
    "car": {
      "color": "blue",
      "price": "$20,000"
    },
    "bus": {
      "color": "white",
      "price": "$120,000"
    }
  }
}

$.vehicles.car.price


---------------------------------------------------------->

{
  "car": {
    "color": "blue",
    "price": "$20,000",
    "wheels": [
      {
        "model": "KDJ39848T",
        "location": "front-right"
      },
      {
        "model": "MDJ39485DK",
        "location": "front-left"
      },
      {
        "model": "KCMDD3435K",
        "location": "rear-right"
      },
      {
        "model": "JJDH34234KK",
        "location": "rear-left"
      }
    ]
  }
}

$.car.wheels
$.car.wheels[2]
$.car.wheels[2].model


---------------------------------------------------->
{
  "employee": {
    "name": "john",
    "gender": "male",
    "age": 24,
    "address": {
      "city": "edison",
      "state": "new jersey",
      "country": "united states"
    },
    "payslips": [
      {
        "month": "june",
        "amount": 1400
      },
      {
        "month": "july",
        "amount": 2400
      },
      {
        "month": "august",
        "amount": 3400
      }
    ]
  }
}

$.employee.payslips


----------------------------------->
{
  "prizes": [
    {
      "year": "2018",
      "category": "physics",
      "overallMotivation": "\"for groundbreaking inventions in the field of laser physics\"",
      "laureates": [
        {
          "id": "960",
          "firstname": "Arthur",
          "surname": "Ashkin",
          "motivation": "\"for the optical tweezers and their application to biological systems\"",
          "share": "2"
        },
        {
          "id": "961",
          "firstname": "Gérard",
          "surname": "Mourou",
          "motivation": "\"for their method of generating high-intensity, ultra-short optical pulses\"",
          "share": "4"
        },
        {
          "id": "962",
          "firstname": "Donna",
          "surname": "Strickland",
          "motivation": "\"for their method of generating high-intensity, ultra-short optical pulses\"",
          "share": "4"
        }
      ]
    },
    {
      "year": "2018",
      "category": "chemistry",
      "laureates": [
        {
          "id": "963",
          "firstname": "Frances H.",
          "surname": "Arnold",
          "motivation": "\"for the directed evolution of enzymes\"",
          "share": "2"
        },
        {
          "id": "964",
          "firstname": "George P.",
          "surname": "Smith",
          "motivation": "\"for the phage display of peptides and antibodies\"",
          "share": "4"
        },
        {
          "id": "965",
          "firstname": "Sir Gregory P.",
          "surname": "Winter",
          "motivation": "\"for the phage display of peptides and antibodies\"",
          "share": "4"
        }
      ]
    },
    {
      "year": "2018",
      "category": "medicine",
      "laureates": [
        {
          "id": "958",
          "firstname": "James P.",
          "surname": "Allison",
          "motivation": "\"for their discovery of cancer therapy by inhibition of negative immune regulation\"",
          "share": "2"
        },
        {
          "id": "959",
          "firstname": "Tasuku",
          "surname": "Honjo",
          "motivation": "\"for their discovery of cancer therapy by inhibition of negative immune regulation\"",
          "share": "2"
        }
      ]
    },
    {
      "year": "2018",
      "category": "peace",
      "laureates": [
        {
          "id": "966",
          "firstname": "Denis",
          "surname": "Mukwege",
          "motivation": "\"for their efforts to end the use of sexual violence as a weapon of war and armed conflict\"",
          "share": "2"
        },
        {
          "id": "967",
          "firstname": "Nadia",
          "surname": "Murad",
          "motivation": "\"for their efforts to end the use of sexual violence as a weapon of war and armed conflict\"",
          "share": "2"
        }
      ]
    },
    {
      "year": "2018",
      "category": "economics",
      "laureates": [
        {
          "id": "968",
          "firstname": "William D.",
          "surname": "Nordhaus",
          "motivation": "\"for integrating climate change into long-run macroeconomic analysis\"",
          "share": "2"
        },
        {
          "id": "969",
          "firstname": "Paul M.",
          "surname": "Romer",
          "motivation": "\"for integrating technological innovations into long-run macroeconomic analysis\"",
          "share": "2"
        }
      ]
    },
    {
      "year": "2014",
      "category": "peace",
      "laureates": [
        {
          "id": "913",
          "firstname": "Kailash",
          "surname": "Satyarthi",
          "motivation": "\"for their struggle against the suppression of children and young people and for the right of all children to education\"",
          "share": "2"
        },
        {
          "id": "914",
          "firstname": "Malala",
          "surname": "Yousafzai",
          "motivation": "\"for their struggle against the suppression of children and young people and for the right of all children to education\"",
          "share": "2"
        }
      ]
    },
    {
      "year": "2017",
      "category": "physics",
      "laureates": [
        {
          "id": "941",
          "firstname": "Rainer",
          "surname": "Weiss",
          "motivation": "\"for decisive contributions to the LIGO detector and the observation of gravitational waves\"",
          "share": "2"
        },
        {
          "id": "942",
          "firstname": "Barry C.",
          "surname": "Barish",
          "motivation": "\"for decisive contributions to the LIGO detector and the observation of gravitational waves\"",
          "share": "4"
        },
        {
          "id": "943",
          "firstname": "Kip S.",
          "surname": "Thorne",
          "motivation": "\"for decisive contributions to the LIGO detector and the observation of gravitational waves\"",
          "share": "4"
        }
      ]
    },
    {
      "year": "2017",
      "category": "chemistry",
      "laureates": [
        {
          "id": "944",
          "firstname": "Jacques",
          "surname": "Dubochet",
          "motivation": "\"for developing cryo-electron microscopy for the high-resolution structure determination of biomolecules in solution\"",
          "share": "3"
        },
        {
          "id": "945",
          "firstname": "Joachim",
          "surname": "Frank",
          "motivation": "\"for developing cryo-electron microscopy for the high-resolution structure determination of biomolecules in solution\"",
          "share": "3"
        },
        {
          "id": "946",
          "firstname": "Richard",
          "surname": "Henderson",
          "motivation": "\"for developing cryo-electron microscopy for the high-resolution structure determination of biomolecules in solution\"",
          "share": "3"
        }
      ]
    },
    {
      "year": "2017",
      "category": "medicine",
      "laureates": [
        {
          "id": "938",
          "firstname": "Jeffrey C.",
          "surname": "Hall",
          "motivation": "\"for their discoveries of molecular mechanisms controlling the circadian rhythm\"",
          "share": "3"
        },
        {
          "id": "939",
          "firstname": "Michael",
          "surname": "Rosbash",
          "motivation": "\"for their discoveries of molecular mechanisms controlling the circadian rhythm\"",
          "share": "3"
        },
        {
          "id": "940",
          "firstname": "Michael W.",
          "surname": "Young",
          "motivation": "\"for their discoveries of molecular mechanisms controlling the circadian rhythm\"",
          "share": "3"
        }
      ]
    }
  ]
}

$.prizes[5].laureates[1]

$.prizes[?(@.year==2014)].laureates[*].name

----------------------------------------------------->
[
  "car",
  "bus",
  "truck",
  "bike"
]

$[0]
$[0,3]

----------------------------->
{
  "property1": "value1",
  "property2": "value2"
}

$.*

jsonpath_queries

jsonpath_queries
MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o wide
NAME       STATUS   ROLES                  AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION    CONTAINER-RUNTIME
minikube   Ready    control-plane,master   25d   v1.20.2   192.168.49.2   <none>        Ubuntu 20.04.2 LTS   5.4.39-linuxkit   docker://20.10.6
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 


MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o json | jq
{
  "apiVersion": "v1",
  "items": [
    {
      "apiVersion": "v1",
      "kind": "Node",
      "metadata": {
        "annotations": {
          "kubeadm.alpha.kubernetes.io/cri-socket": "/var/run/dockershim.sock",
          "node.alpha.kubernetes.io/ttl": "0",
          "volumes.kubernetes.io/controller-managed-attach-detach": "true"
        },
        "creationTimestamp": "2021-09-04T06:52:20Z",
        "labels": {
          "beta.kubernetes.io/arch": "amd64",
          "beta.kubernetes.io/os": "linux",
          "color": "blue",
          "kubernetes.io/arch": "amd64",
          "kubernetes.io/hostname": "minikube",
          "kubernetes.io/os": "linux",
          "minikube.k8s.io/commit": "c61663e942ec43b20e8e70839dcca52e44cd85ae",
          "minikube.k8s.io/name": "minikube",
          "minikube.k8s.io/updated_at": "2021_09_04T14_52_27_0700",
          "minikube.k8s.io/version": "v1.20.0",
          "node-role.kubernetes.io/control-plane": "",
          "node-role.kubernetes.io/master": "",
          "size": "Large"
        },
        "managedFields": [
          {
            "apiVersion": "v1",
            "fieldsType": "FieldsV1",
            "fieldsV1": {
              "f:metadata": {
                "f:annotations": {
                  "f:kubeadm.alpha.kubernetes.io/cri-socket": {}
                },
                "f:labels": {
                  "f:node-role.kubernetes.io/control-plane": {},
                  "f:node-role.kubernetes.io/master": {}
                }
              }
            },
            "manager": "kubeadm",
            "operation": "Update",
            "time": "2021-09-04T06:52:25Z"
          },
          {
            "apiVersion": "v1",
            "fieldsType": "FieldsV1",
            "fieldsV1": {
              "f:metadata": {
                "f:labels": {
                  "f:color": {},
                  "f:minikube.k8s.io/commit": {},
                  "f:minikube.k8s.io/name": {},
                  "f:minikube.k8s.io/updated_at": {},
                  "f:minikube.k8s.io/version": {},
                  "f:size": {}
                }
              }
            },
            "manager": "kubectl-label",
            "operation": "Update",
            "time": "2021-09-17T23:00:31Z"
          },
          {
            "apiVersion": "v1",
            "fieldsType": "FieldsV1",
            "fieldsV1": {
              "f:metadata": {
                "f:annotations": {
                  "f:node.alpha.kubernetes.io/ttl": {}
                }
              },
              "f:spec": {
                "f:podCIDR": {},
                "f:podCIDRs": {
                  ".": {},
                  "v:\"10.244.0.0/24\"": {}
                }
              }
            },
            "manager": "kube-controller-manager",
            "operation": "Update",
            "time": "2021-09-24T12:52:22Z"
          },
          {
            "apiVersion": "v1",
            "fieldsType": "FieldsV1",
            "fieldsV1": {
              "f:metadata": {
                "f:annotations": {
                  ".": {},
                  "f:volumes.kubernetes.io/controller-managed-attach-detach": {}
                },
                "f:labels": {
                  ".": {},
                  "f:beta.kubernetes.io/arch": {},
                  "f:beta.kubernetes.io/os": {},
                  "f:kubernetes.io/arch": {},
                  "f:kubernetes.io/hostname": {},
                  "f:kubernetes.io/os": {}
                }
              },
              "f:status": {
                "f:addresses": {
                  ".": {},
                  "k:{\"type\":\"Hostname\"}": {
                    ".": {},
                    "f:address": {},
                    "f:type": {}
                  },
                  "k:{\"type\":\"InternalIP\"}": {
                    ".": {},
                    "f:address": {},
                    "f:type": {}
                  }
                },
                "f:allocatable": {
                  ".": {},
                  "f:cpu": {},
                  "f:ephemeral-storage": {},
                  "f:hugepages-1Gi": {},
                  "f:hugepages-2Mi": {},
                  "f:memory": {},
                  "f:pods": {}
                },
                "f:capacity": {
                  ".": {},
                  "f:cpu": {},
                  "f:ephemeral-storage": {},
                  "f:hugepages-1Gi": {},
                  "f:hugepages-2Mi": {},
                  "f:memory": {},
                  "f:pods": {}
                },
                "f:conditions": {
                  ".": {},
                  "k:{\"type\":\"DiskPressure\"}": {
                    ".": {},
                    "f:lastHeartbeatTime": {},
                    "f:lastTransitionTime": {},
                    "f:message": {},
                    "f:reason": {},
                    "f:status": {},
                    "f:type": {}
                  },
                  "k:{\"type\":\"MemoryPressure\"}": {
                    ".": {},
                    "f:lastHeartbeatTime": {},
                    "f:lastTransitionTime": {},
                    "f:message": {},
                    "f:reason": {},
                    "f:status": {},
                    "f:type": {}
                  },
                  "k:{\"type\":\"PIDPressure\"}": {
                    ".": {},
                    "f:lastHeartbeatTime": {},
                    "f:lastTransitionTime": {},
                    "f:message": {},
                    "f:reason": {},
                    "f:status": {},
                    "f:type": {}
                  },
                  "k:{\"type\":\"Ready\"}": {
                    ".": {},
                    "f:lastHeartbeatTime": {},
                    "f:lastTransitionTime": {},
                    "f:message": {},
                    "f:reason": {},
                    "f:status": {},
                    "f:type": {}
                  }
                },
                "f:daemonEndpoints": {
                  "f:kubeletEndpoint": {
                    "f:Port": {}
                  }
                },
                "f:images": {},
                "f:nodeInfo": {
                  "f:architecture": {},
                  "f:bootID": {},
                  "f:containerRuntimeVersion": {},
                  "f:kernelVersion": {},
                  "f:kubeProxyVersion": {},
                  "f:kubeletVersion": {},
                  "f:machineID": {},
                  "f:operatingSystem": {},
                  "f:osImage": {},
                  "f:systemUUID": {}
                }
              }
            },
            "manager": "kubelet",
            "operation": "Update",
            "time": "2021-09-24T12:52:32Z"
          },
          {
            "apiVersion": "v1",
            "fieldsType": "FieldsV1",
            "fieldsV1": {
              "f:status": {
                "f:conditions": {
                  "k:{\"type\":\"NetworkUnavailable\"}": {
                    ".": {},
                    "f:lastHeartbeatTime": {},
                    "f:lastTransitionTime": {},
                    "f:message": {},
                    "f:reason": {},
                    "f:status": {},
                    "f:type": {}
                  }
                }
              }
            },
            "manager": "kube-utils",
            "operation": "Update",
            "time": "2021-09-27T07:00:54Z"
          }
        ],
        "name": "minikube",
        "resourceVersion": "201862",
        "uid": "c2ab7942-ba64-4e3f-b6e3-54f11e83082d"
      },
      "spec": {
        "podCIDR": "10.244.0.0/24",
        "podCIDRs": [
          "10.244.0.0/24"
        ]
      },
      "status": {
        "addresses": [
          {
            "address": "192.168.49.2",
            "type": "InternalIP"
          },
          {
            "address": "minikube",
            "type": "Hostname"
          }
        ],
        "allocatable": {
          "cpu": "2",
          "ephemeral-storage": "61255492Ki",
          "hugepages-1Gi": "0",
          "hugepages-2Mi": "0",
          "memory": "2035604Ki",
          "pods": "110"
        },
        "capacity": {
          "cpu": "2",
          "ephemeral-storage": "61255492Ki",
          "hugepages-1Gi": "0",
          "hugepages-2Mi": "0",
          "memory": "2035604Ki",
          "pods": "110"
        },
        "conditions": [
          {
            "lastHeartbeatTime": "2021-09-29T08:05:47Z",
            "lastTransitionTime": "2021-09-29T08:05:47Z",
            "message": "Weave pod has set this",
            "reason": "WeaveIsUp",
            "status": "False",
            "type": "NetworkUnavailable"
          },
          {
            "lastHeartbeatTime": "2021-09-29T08:05:28Z",
            "lastTransitionTime": "2021-09-24T12:52:32Z",
            "message": "kubelet has sufficient memory available",
            "reason": "KubeletHasSufficientMemory",
            "status": "False",
            "type": "MemoryPressure"
          },
          {
            "lastHeartbeatTime": "2021-09-29T08:05:28Z",
            "lastTransitionTime": "2021-09-24T12:52:32Z",
            "message": "kubelet has no disk pressure",
            "reason": "KubeletHasNoDiskPressure",
            "status": "False",
            "type": "DiskPressure"
          },
          {
            "lastHeartbeatTime": "2021-09-29T08:05:28Z",
            "lastTransitionTime": "2021-09-24T12:52:32Z",
            "message": "kubelet has sufficient PID available",
            "reason": "KubeletHasSufficientPID",
            "status": "False",
            "type": "PIDPressure"
          },
          {
            "lastHeartbeatTime": "2021-09-29T08:05:28Z",
            "lastTransitionTime": "2021-09-24T12:52:32Z",
            "message": "kubelet is posting ready status",
            "reason": "KubeletReady",
            "status": "True",
            "type": "Ready"
          }
        ],
        "daemonEndpoints": {
          "kubeletEndpoint": {
            "Port": 10250
          }
        },
        "images": [
          {
            "names": [
              "k8s.gcr.io/etcd@sha256:4ad90a11b55313b182afc186b9876c8e891531b8db4c9bf1541953021618d0e2",
              "k8s.gcr.io/etcd:3.4.13-0"
            ],
            "sizeBytes": 253392289
          },
          {
            "names": [
              "kubernetesui/dashboard@sha256:7f80b5ba141bead69c4fee8661464857af300d7d7ed0274cf7beecedc00322e6",
              "kubernetesui/dashboard:v2.1.0"
            ],
            "sizeBytes": 225733746
          },
          {
            "names": [
              "nginx@sha256:853b221d3341add7aaadf5f81dd088ea943ab9c918766e295321294b035f3f3e",
              "nginx:latest"
            ],
            "sizeBytes": 133283279
          },
          {
            "names": [
              "<none>@<none>",
              "<none>:<none>"
            ],
            "sizeBytes": 133175493
          },
          {
            "names": [
              "k8s.gcr.io/kube-apiserver@sha256:465ba895d578fbc1c6e299e45689381fd01c54400beba9e8f1d7456077411411",
              "k8s.gcr.io/kube-apiserver:v1.20.2"
            ],
            "sizeBytes": 121669114
          },
          {
            "names": [
              "k8s.gcr.io/kube-proxy@sha256:326fe8a4508a5db91cf234c4867eff5ba458bc4107c2a7e15c827a74faa19be9",
              "k8s.gcr.io/kube-proxy:v1.20.2"
            ],
            "sizeBytes": 118400203
          },
          {
            "names": [
              "k8s.gcr.io/kube-controller-manager@sha256:842a071d4ad49b0018f7f7404ac8a4ddfc2bce2ce15b3f8131d89563fda36c9b",
              "k8s.gcr.io/kube-controller-manager:v1.20.2"
            ],
            "sizeBytes": 115852794
          },
          {
            "names": [
              "<none>@<none>",
              "<none>:<none>"
            ],
            "sizeBytes": 105408201
          },
          {
            "names": [
              "weaveworks/weave-kube@sha256:d797338e7beb17222e10757b71400d8471bdbd9be13b5da38ce2ebf597fb4e63",
              "weaveworks/weave-kube:2.8.1"
            ],
            "sizeBytes": 89037656
          },
          {
            "names": [
              "kodekloud/webapp-color@sha256:99c3821ea49b89c7a22d3eebab5c2e1ec651452e7675af243485034a72eb1423",
              "kodekloud/webapp-color:latest"
            ],
            "sizeBytes": 84848908
          },
          {
            "names": [
              "<none>@<none>",
              "<none>:<none>"
            ],
            "sizeBytes": 84758750
          },
          {
            "names": [
              "kodekloud/event-simulator@sha256:1e3e9c72136bbc76c96dd98f29c04f298c3ae241c7d44e2bf70bcc209b030bf9",
              "kodekloud/event-simulator:latest"
            ],
            "sizeBytes": 78221917
          },
          {
            "names": [
              "ubuntu@sha256:9d6a8699fb5c9c39cf08a0871bd6219f0400981c570894cd8cbea30d3424a31f",
              "ubuntu:latest"
            ],
            "sizeBytes": 72776725
          },
          {
            "names": [
              "k8s.gcr.io/metrics-server/metrics-server@sha256:dbc33d7d35d2a9cc5ab402005aa7a0d13be6192f3550c7d42cba8d2d5e3a5d62"
            ],
            "sizeBytes": 60547543
          },
          {
            "names": [
              "k8s.gcr.io/kube-scheduler@sha256:304b3d70497bd62498f19f82f9ef164d38948e5ae94966690abfe9d1858867e2",
              "k8s.gcr.io/kube-scheduler:v1.20.2"
            ],
            "sizeBytes": 46384634
          },
          {
            "names": [
              "k8s.gcr.io/coredns@sha256:73ca82b4ce829766d4f1f10947c3a338888f876fbed0540dc849c89ff256e90c",
              "k8s.gcr.io/coredns:1.7.0"
            ],
            "sizeBytes": 45227747
          },
          {
            "names": [
              "weaveworks/weave-npc@sha256:38d3e30a97a2260558f8deb0fc4c079442f7347f27c86660dbfc8ca91674f14c",
              "weaveworks/weave-npc:2.8.1"
            ],
            "sizeBytes": 39273789
          },
          {
            "names": [
              "kubernetesui/metrics-scraper@sha256:555981a24f184420f3be0c79d4efb6c948a85cfce84034f85a563f4151a81cbf",
              "kubernetesui/metrics-scraper:v1.0.4"
            ],
            "sizeBytes": 36937728
          },
          {
            "names": [
              "gcr.io/k8s-minikube/storage-provisioner@sha256:18eb69d1418e854ad5a19e399310e52808a8321e4c441c1dddad8977a0d7a944",
              "gcr.io/k8s-minikube/storage-provisioner:v5"
            ],
            "sizeBytes": 31465472
          },
          {
            "names": [
              "busybox@sha256:52f73a0a43a16cf37cd0720c90887ce972fe60ee06a687ee71fb93a7ca601df7",
              "busybox:latest"
            ],
            "sizeBytes": 1235724
          },
          {
            "names": [
              "k8s.gcr.io/pause@sha256:927d98197ec1141a368550822d18fa1c60bdae27b78b0c004f705f548c07814f",
              "k8s.gcr.io/pause:3.2"
            ],
            "sizeBytes": 682696
          }
        ],
        "nodeInfo": {
          "architecture": "amd64",
          "bootID": "ec127cba-1d71-4eda-9296-fe1fe4abb570",
          "containerRuntimeVersion": "docker://20.10.6",
          "kernelVersion": "5.4.39-linuxkit",
          "kubeProxyVersion": "v1.20.2",
          "kubeletVersion": "v1.20.2",
          "machineID": "822f5ed6656e44929f6c2cc5d6881453",
          "operatingSystem": "linux",
          "osImage": "Ubuntu 20.04.2 LTS",
          "systemUUID": "182b1b5d-793c-4026-88b4-599941ba1cae"
        }
      }
    }
  ],
  "kind": "List",
  "metadata": {
    "resourceVersion": "",
    "selfLink": ""
  }
}
MacBook-Pro:11.Troubleshooting bharathdasaraju$


MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=jsonpath='{.items[*].metadata.name}' 
minikube
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 

MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=jsonpath='{.items[*].status.nodeInfo}'
{"architecture":"amd64","bootID":"ec127cba-1d71-4eda-9296-fe1fe4abb570","containerRuntimeVersion":"docker://20.10.6","kernelVersion":"5.4.39-linuxkit","kubeProxyVersion":"v1.20.2","kubeletVersion":"v1.20.2","machineID":"822f5ed6656e44929f6c2cc5d6881453","operatingSystem":"linux","osImage":"Ubuntu 20.04.2 LTS","systemUUID":"182b1b5d-793c-4026-88b4-599941ba1cae"}

MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=jsonpath='{.items[*].status.nodeInfo.architecture}'
amd64
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 


amd64MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=jsonpath='{.items[*].status.capacity}'
{"cpu":"2","ephemeral-storage":"61255492Ki","hugepages-1Gi":"0","hugepages-2Mi":"0","memory":"2035604Ki","pods":"110"}
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 

MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=jsonpath='{.items[*].status.capacity.cpu}'
2
MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=jsonpath='{.items[*].metadata.name}{.items[*].status.capacity.cpu}'
minikube2
MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=jsonpath='{.items[*].metadata.name} {.items[*].status.capacity.cpu}'
minikube 2
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 

loops in json path:
------------------------>
MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.capacity.cpu}{"\n"}{end}'
minikube        2
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 

cutom columns in jsonpath:
--------------------------------->
acBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=custom-columns=NODE:.metadata.name
NODE
minikube
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 


MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes -o=custom-columns=NODE:.metadata.name,CPU:.status.capacity.cpu
NODE       CPU
minikube   2
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 


kubectl with --sort-by options:
----------------------------------------------------------------------------------------------------->
MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes --sort-by=.metadata.name
NAME       STATUS   ROLES                  AGE   VERSION
minikube   Ready    control-plane,master   25d   v1.20.2
MacBook-Pro:11.Troubleshooting bharathdasaraju$ kubectl get nodes --sort-by=.status.capacity.cpu
NAME       STATUS   ROLES                  AGE   VERSION
minikube   Ready    control-plane,master   25d   v1.20.2
MacBook-Pro:11.Troubleshooting bharathdasaraju$ 

Question:
------------------------->

The order of container could be different. 
The redis-container need not be the second container all the time. 
So, re-develop a JSON PATH query to get the restart count of redis-container, 
but this time use a criteria/condition to get the restart count of the container with the container name redis-container

Answer:
--------------------------->
$.status.containerStatuses[?(@.name == 'redis-container')].restartCount

{
  "apiVersion": "v1",
  "kind": "Pod",
  "metadata": {
    "name": "nginx-pod",
    "namespace": "default"
  },
  "spec": {
    "containers": [
      {
        "image": "nginx:alpine",
        "name": "nginx"
      },
      {
        "image": "redis:alpine",
        "name": "redis-container"
      }
    ],
    "nodeName": "node01"
  },
  "status": {
    "conditions": [
      {
        "lastProbeTime": null,
        "lastTransitionTime": "2019-06-13T05:34:09Z",
        "status": "True",
        "type": "Initialized"
      },
      {
        "lastProbeTime": null,
        "lastTransitionTime": "2019-06-13T05:34:09Z",
        "status": "True",
        "type": "PodScheduled"
      }
    ],
    "containerStatuses": [
      {
        "image": "nginx:alpine",
        "name": "nginx",
        "ready": false,
        "restartCount": 4,
        "state": {
          "waiting": {
            "reason": "ContainerCreating"
          }
        }
      },
      {
        "image": "redis:alpine",
        "name": "redis-container",
        "ready": false,
        "restartCount": 2,
        "state": {
          "waiting": {
            "reason": "ContainerCreating"
          }
        }
      }
    ],
    "hostIP": "172.17.0.75",
    "phase": "Pending",
    "qosClass": "BestEffort",
    "startTime": "2019-06-13T05:34:09Z"
  }
}

------------------------------------------------------------------------------------------->
[
  {
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {
      "name": "web-pod-1",
      "namespace": "default"
    },
    "spec": {
      "containers": [
        {
          "image": "nginx:alpine",
          "name": "nginx"
        }
      ],
      "nodeName": "node01"
    }
  },
  {
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {
      "name": "web-pod-2",
      "namespace": "default"
    },
    "spec": {
      "containers": [
        {
          "image": "nginx:alpine",
          "name": "nginx"
        }
      ],
      "nodeName": "node02"
    }
  },
  {
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {
      "name": "web-pod-3",
      "namespace": "default"
    },
    "spec": {
      "containers": [
        {
          "image": "nginx:alpine",
          "name": "nginx"
        }
      ],
      "nodeName": "node01"
    }
  },
  {
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {
      "name": "web-pod-4",
      "namespace": "default"
    },
    "spec": {
      "containers": [
        {
          "image": "nginx:alpine",
          "name": "nginx"
        }
      ],
      "nodeName": "node01"
    }
  },
  {
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {
      "name": "db-pod-1",
      "namespace": "default"
    },
    "spec": {
      "containers": [
        {
          "image": "mysql",
          "name": "mysql"
        }
      ],
      "nodeName": "node01"
    }
  }
]


Develop a JSON PATH query to get all pod names.

$[*].metadata.name




{
  "kind": "Config",
  "apiVersion": "v1",
  "preferences": {},
  "clusters": [
    {
      "name": "development",
      "cluster": {
        "server": "KUBE_ADDRESS",
        "certificate-authority": "/etc/kubernetes/pki/ca.crt"
      }
    },
    {
      "name": "kubernetes-on-aws",
      "cluster": {
        "server": "KUBE_ADDRESS",
        "certificate-authority": "/etc/kubernetes/pki/ca.crt"
      }
    },
    {
      "name": "production",
      "cluster": {
        "server": "KUBE_ADDRESS",
        "certificate-authority": "/etc/kubernetes/pki/ca.crt"
      }
    },
    {
      "name": "test-cluster-1",
      "cluster": {
        "server": "KUBE_ADDRESS",
        "certificate-authority": "/etc/kubernetes/pki/ca.crt"
      }
    }
  ],
  "users": [
    {
      "name": "aws-user",
      "user": {
        "client-certificate": "/etc/kubernetes/pki/users/aws-user/aws-user.crt",
        "client-key": "/etc/kubernetes/pki/users/aws-user/aws-user.key"
      }
    },
    {
      "name": "dev-user",
      "user": {
        "client-certificate": "/etc/kubernetes/pki/users/dev-user/developer-user.crt",
        "client-key": "/etc/kubernetes/pki/users/dev-user/dev-user.key"
      }
    },
    {
      "name": "test-user",
      "user": {
        "client-certificate": "/etc/kubernetes/pki/users/test-user/test-user.crt",
        "client-key": "/etc/kubernetes/pki/users/test-user/test-user.key"
      }
    }
  ],
  "contexts": [
    {
      "name": "aws-user@kubernetes-on-aws",
      "context": {
        "cluster": "kubernetes-on-aws",
        "user": "aws-user"
      }
    },
    {
      "name": "research",
      "context": {
        "cluster": "test-cluster-1",
        "user": "dev-user"
      }
    },
    {
      "name": "test-user@development",
      "context": {
        "cluster": "development",
        "user": "test-user"
      }
    },
    {
      "name": "test-user@production",
      "context": {
        "cluster": "production",
        "user": "test-user"
      }
    }
  ],
  "current-context": "test-user@development"
}


Develop a JSON PATH query to get all user names.
$.users[*].name

jsonpath_k8s

jsonpath_k8s
root@controlplane:~# kubectl get nodes -o=jsonpath='{.items[*].metadata.name}'     
controlplane node01
root@controlplane:~# 


root@controlplane:~# kubectl get nodes -o=jsonpath='{.items[*].metadata.name}' > /opt/outputs/node_names.txt
root@controlplane:~# cat /opt/outputs/node_names.txt
controlplane node01
root@controlplane:~# 



root@controlplane:~# kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os.txt
root@controlplane:~#  kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}'
Ubuntu 18.04.5 LTS Ubuntu 18.04.5 LTS
root@controlplane:~# 


root@controlplane:~# kubectl config view --kubeconfig=/root/my-kube-config 
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: KUBE_ADDRESS
  name: development
- cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: KUBE_ADDRESS
  name: kubernetes-on-aws
- cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: KUBE_ADDRESS
  name: production
- cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: KUBE_ADDRESS
  name: test-cluster-1
contexts:
- context:
    cluster: kubernetes-on-aws
    user: aws-user
  name: aws-user@kubernetes-on-aws
- context:
    cluster: test-cluster-1
    user: dev-user
  name: research
- context:
    cluster: development
    user: test-user
  name: test-user@development
- context:
    cluster: production
    user: test-user
  name: test-user@production
current-context: test-user@development
kind: Config
preferences: {}
users:
- name: aws-user
  user:
    client-certificate: /etc/kubernetes/pki/users/aws-user/aws-user.crt
    client-key: /etc/kubernetes/pki/users/aws-user/aws-user.key
- name: dev-user
  user:
    client-certificate: /etc/kubernetes/pki/users/dev-user/developer-user.crt
    client-key: /etc/kubernetes/pki/users/dev-user/dev-user.key
- name: test-user
  user:
    client-certificate: /etc/kubernetes/pki/users/test-user/test-user.crt
    client-key: /etc/kubernetes/pki/users/test-user/test-user.key
root@controlplane:~# 


root@controlplane:~# kubectl config view --kubeconfig=/root/my-kube-config -o jsonpath="{.users[*].name}"
aws-user dev-user test-user
root@controlplane:~#


root@controlplane:~# kubectl get pv
NAME       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
pv-log-1   100Mi      RWX            Retain           Available                                   15m
pv-log-2   200Mi      RWX            Retain           Available                                   15m
pv-log-3   300Mi      RWX            Retain           Available                                   15m
pv-log-4   40Mi       RWX            Retain           Available                                   15m
root@controlplane:~# 

root@controlplane:~# kubectl get pv --sort-by=.spec.capacity.storage
NAME       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
pv-log-4   40Mi       RWX            Retain           Available                                   18m
pv-log-1   100Mi      RWX            Retain           Available                                   18m
pv-log-2   200Mi      RWX            Retain           Available                                   18m
pv-log-3   300Mi      RWX            Retain           Available                                   18m
root@controlplane:~# 


kubectl get pv --sort-by=.spec.capacity.storage -o=custom-columns=NAME:.metadata.name,CAPACITY:.spec.capacity.storage



root@controlplane:~# kubectl get pv --sort-by=.spec.capacity.storage -o=custom-columns=NAME:.metadata.name,CAPACITY:.spec.capacity.storage
NAME       CAPACITY
pv-log-4   40Mi
pv-log-1   100Mi
pv-log-2   200Mi
pv-log-3   300Mi
root@controlplane:~# 


root@controlplane:~# kubectl config view --kubeconfig=my-kube-config -o jsonpath="{.contexts[?(@.context.user=='aws-user')].name}"
aws-user@kubernetes-on-aws
root@controlplane:~#