Skip to content

K8S Probe

With the proliferation of custom resources & operators, especially in the case of stateful applications, the steady-state is manifested as status parameters/flags within Kubernetes resources. k8sProbe addresses verification of the desired resource state by allowing users to define the Kubernetes GVR (group-version-resource) with appropriate filters (field selectors/label selectors). The experiment makes use of the Kubernetes Dynamic Client to achieve this. It supports CRUD operations which can be defined at probe.k8sProbe/inputs.operation. It can be executed by setting type as k8sProbe inside .spec.experiments[].spec.probe.

View the k8s probe schema

Field .name
Description Flag to hold the name of the probe
Type Mandatory
Range n/a (type: string)
Notes The .name holds the name of the probe. It can be set based on the usecase

Field .type
Description Flag to hold the type of the probe
Type Mandatory
Range httpProbe, k8sProbe, cmdProbe, promProbe
Notes The .type supports four type of probes. It can one of the httpProbe, k8sProbe, cmdProbe, promProbe

Field .mode
Description Flag to hold the mode of the probe
Type Mandatory
Range SOT, EOT, Edge, Continuous, OnChaos
Notes The .mode supports five modes of probes. It can one of the SOT, EOT, Edge, Continuous, OnChaos

Field .k8sProbe/inputs.group
Description Flag to hold the group of the kubernetes resource for the k8sProbe
Type Mandatory
Range n/a {type: string}
Notes The .k8sProbe/inputs.group contains group of the kubernetes resource on which k8sProbe performs the specified operation

Field .k8sProbe/inputs.version
Description Flag to hold the apiVersion of the kubernetes resource for the k8sProbe
Type Mandatory
Range n/a {type: string}
Notes The .k8sProbe/inputs.version contains apiVersion of the kubernetes resource on which k8sProbe performs the specified operation

Field .k8sProbe/inputs.resource
Description Flag to hold the kubernetes resource name for the k8sProbe
Type Mandatory
Range n/a {type: string}
Notes The .k8sProbe/inputs.resource contains the kubernetes resource name on which k8sProbe performs the specified operation

Field .k8sProbe/inputs.namespace
Description Flag to hold the namespace of the kubernetes resource for the k8sProbe
Type Mandatory
Range n/a {type: string}
Notes The .k8sProbe/inputs.namespace contains namespace of the kubernetes resource on which k8sProbe performs the specified operation

Field .k8sProbe/inputs.fieldSelector
Description Flag to hold the fieldSelectors of the kubernetes resource for the k8sProbe
Type Optional
Range n/a {type: string}
Notes The .k8sProbe/inputs.fieldSelector contains fieldSelector to derived the kubernetes resource on which k8sProbe performs the specified operation

Field .k8sProbe/inputs.labelSelector
Description Flag to hold the labelSelectors of the kubernetes resource for the k8sProbe
Type Optional
Range n/a {type: string}
Notes The .k8sProbe/inputs.labelSelector contains labelSelector to derived the kubernetes resource on which k8sProbe performs the specified operation

Field .k8sProbe/inputs.operation
Description Flag to hold the operation type for the k8sProbe
Type Mandatory
Range create, delete, present, absent
Notes The .k8sProbe/inputs.operation contains operation which should be applied on the kubernetes resource as part of k8sProbe. It supports four type of operation. It can be one of create, delete, present, absent.

Field .runProperties.probeTimeout
Description Flag to hold the timeout for the probes
Type Mandatory
Range n/a {type: integer}
Notes The .runProperties.probeTimeout represents the time limit for the probe to execute the specified check and return the expected data

Field .runProperties.retry
Description Flag to hold the retry count for the probes
Type Mandatory
Range n/a {type: integer}
Notes The .runProperties.retry contains the number of times a check is re-run upon failure in the first attempt before declaring the probe status as failed.

Field .runProperties.interval
Description Flag to hold the interval for the probes
Type Mandatory
Range n/a {type: integer}
Notes The .runProperties.interval contains the interval for which probes waits between subsequent retries

Field .runProperties.probePollingInterval
Description Flag to hold the polling interval for the probes(applicable for Continuous mode only)
Type Optional
Range n/a {type: integer}
Notes The .runProperties.probePollingInterval contains the time interval for which continuous probe should be sleep after each iteration

Field .runProperties.initialDelaySeconds
Description Flag to hold the initial delay interval for the probes
Type Optional
Range n/a {type: integer}
Notes The .runProperties.initialDelaySeconds represents the initial waiting time interval for the probes.

Field .runProperties.stopOnFailure
Description Flags to hold the stop or continue the experiment on probe failure
Type Optional
Range false {type: boolean}
Notes The .runProperties.stopOnFailure can be set to true/false to stop or continue the experiment execution after probe fails

Common Probe Tunables

Refer the common attributes to tune the common tunables for all the probes.

Create Operation

It creates kubernetes resource based on the data provided inside probe.data field. It can be defined by setting operation to create operation.

Use the following example to tune this:

# create the given resource provided inside data field
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: engine-nginx
spec:
  engineState: "active"
  appinfo:
    appns: "default"
    applabel: "app=nginx"
    appkind: "deployment"
  chaosServiceAccount: pod-delete-sa
  experiments:
  - name: pod-delete
    spec:
      probe:
      - name: "create-percona-pvc"
        type: "k8sProbe"
        k8sProbe/inputs:
          # group of the resource
          group: ""
          # version of the resource
          version: "v1"
          # name of the resource
          resource: "persistentvolumeclaims"
          # namespace where the instance of resource should be created
          namespace: "default"
          # type of operation
          # supports: create, delete, present, absent
          operation: "create"
        mode: "SOT"
        runProperties:
          probeTimeout: 5 
          interval: 2 
          retry: 1
        # contains manifest, which can be used to create the resource
        data: |
          kind: PersistentVolumeClaim
          apiVersion: v1
          metadata:
            name: percona-mysql-claim
            labels:
              openebs.io/target-affinity: percona
          spec:
            storageClassName: standard
            accessModes:
            - ReadWriteOnce
            resources:
              requests:
                storage: 100Mi

Delete Operation

It deletes matching kubernetes resources via GVR and filters (field selectors/label selectors) provided at probe.k8sProbe/inputs. It can be defined by setting operation to delete operation.

Use the following example to tune this:

# delete the resource matched with the given inputs
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: engine-nginx
spec:
  engineState: "active"
  appinfo:
    appns: "default"
    applabel: "app=nginx"
    appkind: "deployment"
  chaosServiceAccount: pod-delete-sa
  experiments:
  - name: pod-delete
    spec:
      probe:
      - name: "delete-percona-pvc"
        type: "k8sProbe"
        k8sProbe/inputs:
          # group of the resource
          group: ""
          # version of the resource
          version: "v1"
          # name of the resource
          resource: "persistentvolumeclaims"
          # namespace of the instance, which needs to be deleted
          namespace: "default"
          # labels selectors for the k8s resource, which needs to be deleted
          labelSelector: "openebs.io/target-affinity=percona"
          # fieldselector for the k8s resource, which needs to be deleted
          fieldSelector: ""
          # type of operation
          # supports: create, delete, present, absent
          operation: "delete"
        mode: "EOT"
        runProperties:
          probeTimeout: 5 
          interval: 2 
          retry: 1

Present Operation

It checks for the presence of kubernetes resource based on GVR and filters (field selectors/labelselectors) provided at probe.k8sProbe/inputs. It can be defined by setting operation to present operation.

Use the following example to tune this:

# verify the existance of the resource matched with the given inputs inside cluster
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: engine-nginx
spec:
  engineState: "active"
  appinfo:
    appns: "default"
    applabel: "app=nginx"
    appkind: "deployment"
  chaosServiceAccount: pod-delete-sa
  experiments:
  - name: pod-delete
    spec:
      probe:
      - name: "check-percona-pvc-presence"
        type: "k8sProbe"
        k8sProbe/inputs:
          # group of the resource
          group: ""
          # version of the resource
          version: "v1"
          # name of the resource
          resource: "persistentvolumeclaims"
          # namespace where the instance of resource
          namespace: "default"
          # labels selectors for the k8s resource
          labelSelector: "openebs.io/target-affinity=percona"
          # fieldselector for the k8s resource
          fieldSelector: ""
          # type of operation
          # supports: create, delete, present, absent
          operation: "present"
        mode: "SOT"
        runProperties:
          probeTimeout: 5 
          interval: 2 
          retry: 1

Absent Operation

It checks for the absence of kubernetes resource based on GVR and filters (field selectors/labelselectors) provided at probe.k8sProbe/inputs. It can be defined by setting operation to absent operation.

Use the following example to tune this:

# verify that the no resource should be present in cluster with the given inputs
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: engine-nginx
spec:
  engineState: "active"
  appinfo:
    appns: "default"
    applabel: "app=nginx"
    appkind: "deployment"
  chaosServiceAccount: pod-delete-sa
  experiments:
  - name: pod-delete
    spec:
      probe:
      - name: "check-percona-pvc-absence"
        type: "k8sProbe"
        k8sProbe/inputs:
          # group of the resource
          group: ""
          # version of the resource
          version: "v1"
          # name of the resource
          resource: "persistentvolumeclaims"
          # namespace where the instance of resource
          namespace: "default"
          # labels selectors for the k8s resource
          labelSelector: "openebs.io/target-affinity=percona"
          # fieldselector for the k8s resource
          fieldSelector: ""
          # type of operation
          # supports: create, delete, present, absent
          operation: "absent"
        mode: "EOT"
        runProperties:
          probeTimeout: 5 
          interval: 2 
          retry: 1