FreeKB - OpenShift Create Secret using the oc secrets command
OpenShift - Create Secret using the oc secrets command

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

You may want to use the oc get secrets command to display the secrets that have already been created.

oc get secrets

NAME           TYPE        DATA      AGE
mysecret1      Opaque      1         133d
mysecret2      Opaque      1         133d
mysecret3      Opaque      1         127d

 

Let's say you want to create a secret named "mysecret4" where the secret contains key "foo" with a value of "bar". This could be done using the oc create secret command, or using the oc apply command. This article describes how to create the secret using the oc create secret command.

With the oc create secrets command, there are two different command line options that can be used.

  • --from-literal
  • --from-file

 

If using the --from-file option, you'll need to create a file that will contain the secret content. Let's say you name the file secret.yml and the file contains the following.

username=john.doe
password=foo

 

Here is how you would use the oc create secret command with the --from-file option.

oc create secret generic mysecret --from-file=secret.yml

 

And here is how you would create a secret where the key is "foo" and the value is "bar" using the --from-literal option.

oc create secret generic mysecret --from-literal=foo="bar"

 

If the secret is successfully created, the following will be displayed.

secret "mysecret" created

 

Here is what the secret will look like in the OpenShift admin console.

 


Multiple keys

Let's say you have 2 files, where the file named "key1" contains:

username=john.doe
password=foo

 

And the file named "key2" contains:

username=jane.doe
password=bar

 

In this scenario, you would include both files on the command line.

oc create secret generic mysecret --from-file=key1 --from-file=key2

 

If the secret is successfully created, the following will be displayed.

secret "mysecret" created

 

Here is what the secret will look like in the OpenShift admin console.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter c16cd in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |