Before You Begin

Let's confirm our current namespace in the Kubernetes cluster. Next, let's create a new namespace and a new Kubernetes Secret in that namespace. The examples use these two namespaces.

  1. Confirm the current namespace and review the Secrets in the namespace.
    1. Confirm the current namespace.
      kubectl config view | grep namespace
      The output is similar to the following:
          namespace: mynamespace

      The current namespace is mynamespace.

    2. Confirm the Secret in the namespace.
      kubectl get secrets

      The output is similar to the following:

      NAME                                                                TYPE                             DATA   AGE
      ...
      sekret                                                              kubernetes.io/dockerconfigjson   1      15d
      ...

      The sekret Secret exists in the mynamespace namespace.

  2. Create a new namespace and create a Kubernetes Secret in the namespace.
    1. Create a new namespace.
      kubectl create namespace mynamespace2

      The output is similar to the following:

      namespace/mynamespace2 created
    2. Switch to the new namespace.
      kubectl config set-context --current --namespace=mynamespace2

      The output is similar to the following:

      Context "default" modified.
    3. Confirm the current namespace.
      kubectl config view | grep namespace

      The output is similar to the following:

          namespace: mynamespace2
    4. Create a Kubernetes Secret in this namespace.
      kubectl create secret generic sekret --from-file=.dockerconfigjson=$HOME/.docker/config.json --type=kubernetes.io/dockerconfigjson

      The output is the following:

      secret/sekret created
  3. Confirm the namespaces.
    kubectl get namespaces

    The output is similar to the following:

    NAME              STATUS   AGE
    mynamespace       Active   15d
    ...
    mynamespace2      Active   49m
You confirmed the namespaces in your Kubernetes cluster.