Skip to content

kubee-lib

A library of kubernetes functions

A library of kubernetes functions

Return the app name and namespace from a string A qualified app name is made of one optional namespace and a name separated by a slash

Terminal window
read APP_NAMESPACE APP_NAME <<< "$(kube::get_qualified_app_name "$APP_NAME")"
  • $1 (string): The app name
  • The app label ie app.kubernetes.io/name=<app name>

Return the app label used to locate resources It will return the label app.kubernetes.io/name=<app name> This is the common app label as seen on the common label page

Terminal window
APP_LABEL="$(kubee::get_app_label "$APP_NAME")"
  • $1 (string): The app name
  • The app label ie app.kubernetes.io/name=<app name>

Function to search for resources across all namespaces by app name and returns data about them

Terminal window
PODS="$(kube::get_resources_by_app_name --type pod "$APP_NAME")"
  • $1 (string): x - the app name (mandatory) used in the label “app.kubernetes.io/name=$APP_NAME”
  • $2 (string): --type x - the resource type: pod, … (mandatory)
  • $3 (string): --custom-columns x - the custom columns (Default to NAME:.metadata.name,NAMESPACE:.metadata.namespace)
  • $4 (string): --headers - the headers (Default to no headers)
  • The resources data (one resource by line) or an empty string

Function to search for 1 resource across all namespaces by app name and returns data

Terminal window
read -r POD_NAME POD_NAMESPACE <<< "$(kubee::get_resource_by_app_name --type pod "$APP_NAME" )"
if [ -z "$POD_NAME" ]; then
echo "Error: Pod not found with label $(kubee::get_app_label $APP_NAME)"
exit 1
fi
  • $1 (string): x - The app name
  • $2 (string): --type type - The resource type (pod, …)
  • $3 (string): --custom-columns x - the custom columns (Default to NAME:.metadata.name,NAMESPACE:.metadata.namespace)
  • $4 (string): --headers - the headers (Default to no headers)
  • 1: - if too many resource was found
  • The resource name and namespace separated by a space or an empty string

Return a json path to be used in a -o jsonpath=x kubectl option

  • $1 (string): The Json expressions (Default to: .metadata.name .metadata.namespace)

test the connection to the cluster

  • 1: - if the connection did not succeed

Return the directory of a cluster

  • $1 (string): The package name