how to know namespace is present or not in kubernetes shell script 1

how to know namespace is present or not in kubernetes shell script

#!/bin/bash

namespaceStatus=$(kubectl get ns nightlybuild-test -o json | jq .status.phase -r)
if [ $namespaceStatus == "Active" ]
then
    echo "namespace is present"
else
   echo "namespace is not present"

Here is what the above code is Doing:
1. It’s checking if the namespace is present or not.
2. If the namespace is present, it will print “namespace is present”
3. If the namespace is not present, it will print “namespace is not present”

Similar Posts