{"id":1494,"date":"2021-04-12T09:35:03","date_gmt":"2021-04-12T09:35:03","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=1494"},"modified":"2021-04-12T09:35:05","modified_gmt":"2021-04-12T09:35:05","slug":"secrets","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2021\/04\/12\/secrets\/","title":{"rendered":"Secrets"},"content":{"rendered":"\n<p>To manage sensitive information you create <code>secrets<\/code><\/p>\n\n\n\n<pre id=\"block-d19cc57e-b74f-49e9-89a4-b25c3195b543\" class=\"wp-block-code\"><code>k create secret --help<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Create a secret using specified subcommand.\n\nAvailable Commands:\n  docker-registry Create a secret for use with a Docker registry\n  generic         Create a secret from a local file, directory or literal value\n  tls             Create a TLS secret\n\nUsage:\n  kubectl create secret &#91;flags] &#91;options]\n\nUse \"kubectl &lt;command> --help\" for more information about a given command.\nUse \"kubectl options\" for a list of global command-line options (applies to all commands).<\/code><\/pre>\n\n\n\n<p><code>type<\/code> specifies the type of secret you are creating (options are as shown above). As I need to create only key value pairs for my dummy secret file I need to know a way of how to facilitate that, and the option <code>-h<\/code> helped me there<\/p>\n\n\n\n<p>Further looking at the options for <code>generic<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>k create secret generic -h<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Create a secret based on a file, directory, or specified literal value.\n\n A single secret may package one or more key\/value pairs.\n\n When creating a secret based on a file, the key will default to the basename of the file, and the value will default to\nthe file content. If the basename is an invalid key or you wish to chose your own, you may specify an alternate key.\n\n When creating a secret based on a directory, each file whose basename is a valid key in the directory will be packaged\ninto the secret. Any directory entries except regular files are ignored (e.g. subdirectories, symlinks, devices, pipes,\netc).\n\nExamples:\n  # Create a new secret named my-secret with keys for each file in folder bar\n  kubectl create secret generic my-secret --from-file=path\/to\/bar\n  \n  # Create a new secret named my-secret with specified keys instead of names on disk\n  kubectl create secret generic my-secret --from-file=ssh-privatekey=path\/to\/id_rsa\n--from-file=ssh-publickey=path\/to\/id_rsa.pub\n  \n  # Create a new secret named my-secret with key1=supersecret and key2=topsecret\n  kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret\n  \n  # Create a new secret named my-secret using a combination of a file and a literal\n  kubectl create secret generic my-secret --from-file=ssh-privatekey=path\/to\/id_rsa --from-literal=passphrase=topsecret\n  \n  # Create a new secret named my-secret from an env file\n  kubectl create secret generic my-secret --from-env-file=path\/to\/bar.env\n\nOptions:\n      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in\nthe template. Only applies to golang and jsonpath output formats.\n      --append-hash=false: Append a hash of the secret to its name.\n      --dry-run='none': Must be \"none\", \"server\", or \"client\". If client strategy, only print the object that would be\nsent, without sending it. If server strategy, submit server-side request without persisting the resource.\n      --field-manager='kubectl-create': Name of the manager used to track field ownership.\n      --from-env-file='': Specify the path to a file to read lines of key=val pairs to create a secret (i.e. a Docker\n.env file).\n      --from-file=&#91;]: Key files can be specified using their file path, in which case a default name will be given to\nthem, or optionally with a name and file path, in which case the given name will be used.  Specifying a directory will\niterate each named file in the directory that is a valid secret key.\n      --from-literal=&#91;]: Specify a key and literal value to insert in secret (i.e. mykey=somevalue)\n  -o, --output='': Output format. One of:\njson|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file.\n      --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the\nannotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.\n      --show-managed-fields=false: If true, keep the managedFields when printing objects in JSON or YAML format.\n      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The\ntemplate format is golang templates &#91;http:\/\/golang.org\/pkg\/text\/template\/#pkg-overview].\n      --type='': The type of secret to create\n      --validate=true: If true, use a schema to validate the input before sending it\n\nUsage:\n  kubectl create secret generic NAME &#91;--type=string] &#91;--from-file=&#91;key=]source] &#91;--from-literal=key1=value1]\n&#91;--dry-run=server|client|none] &#91;options]\n\nUse \"kubectl options\" for a list of global command-line options (applies to all commands).<\/code><\/pre>\n\n\n\n<p>I will use <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>k create secret generic samrthya --from-literal=\"supersecret=mypassword\"\nsecret\/samrthya created<\/code><\/pre>\n\n\n\n<p>You can look at the details below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>k describe secret\/samrthya\nName:         samrthya\nNamespace:    default\nLabels:       &lt;none>\nAnnotations:  &lt;none>\n\nType:  Opaque\n\nData\n====\nsupersecret:  10 bytes<\/code><\/pre>\n\n\n\n<p>I tried editing the file by using <code>k edit<\/code> and the resource name, and in my case it shows up base64 encoded<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Please edit the object below. Lines beginning with a '#' will be ignored,\n# and an empty file will abort the edit. If an error occurs while saving this file will be\n# reopened with the relevant failures.\n#\napiVersion: v1\ndata:\n  supersecret: bXlwYXNzd29yZA==\nkind: Secret\nmetadata:\n  creationTimestamp: \"2021-04-12T09:12:04Z\"\n  name: samrthya\n  namespace: default\n  resourceVersion: \"22555526\"\n  selfLink: \/api\/v1\/namespaces\/default\/secrets\/samrthya\n  uid: 09db0ea3-3885-4354-9c16-4a9859c6a201\ntype: Opaque\n~            <\/code><\/pre>\n\n\n\n<p>Optionally you can define a <code>YAML file<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"kind\": \"Secret\",\n    \"apiVersion\": \"v1\",\n    \"metadata\": {\n        \"name\": \"samrthya\"\n    },\n    \"data\": {\n        \"supersecret\": \"bXlwYXNzd29yZA==\"\n    }\n}<\/code><\/pre>\n\n\n\n<p>You can also do a listing <\/p>\n\n\n\n<pre id=\"block-f2e9a7d5-9260-48fb-abf9-369f91454416\" class=\"wp-block-code\"><code>k get secret<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME                            TYPE                                  DATA   AGE\nsamrthya                        Opaque                                1      3m47s<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Help<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/v1-18.docs.kubernetes.io\/docs\/reference\/generated\/kubernetes-api\/v1.18\/#secret-v1-core\">https:\/\/v1-18.docs.kubernetes.io\/docs\/reference\/generated\/kubernetes-api\/v1.18\/#secret-v1-core<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>To manage sensitive information you create secrets type specifies the type of secret you are creating (options are as shown above). As I need to create only key value pairs for my dummy secret file I need to know a way of how to facilitate that, and the option -h helped me there Further looking [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1380,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[18,178],"class_list":["post-1494","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","tag-k8s","tag-secrets","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=1494"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1494\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/1380"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=1494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=1494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=1494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}