I've created a secret okay by doing this...kubectl create secret generic <namespace> <secret-name> --from-literal=value1=xxxx --from-literal=value2=xxxx --from-literal=value3=xxxx
When I do a get command I get
apiVersion: v1
data:
value1: xxxx
value2: xxxx
value3: xxxx
kind: Secret
metadata:
creationTimestamp: <time>
name: <secret-name>
namespace: <namespace>
resourceVersion: <version number>
uid: <alpha-numeric>
type: Opaque
...the thing is...I was expecting to automatically include an annotations section below where it says metadata so that it should looks more like
apiVersion: v1
data:
value1: xxxx
value2: xxxx
value3: xxxx
kind: Secret
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"value1":<api>,"value2":<portalid> ,"value3" <reporting-
id>},"kind":"Secret","metadata":{"annotations":{},"name":"<secret-name>","namespace":"
<namespace>"},"type":"Opaque"}
creationTimestamp: <time>
name: <secret-name>
namespace: <namespace>
resourceVersion: <version number>
uid: <alpha-numeric>
type: Opaque
Is this ONLY possible if you add the secret from a file or is there away you can add this annotation information via the string literal..I've been searching the internet but the only solution I can find is via a file...not through a string as such....can anybody help?
CodePudding user response:
Is this ONLY possible if you add the secret from a file
yes, this is used to compare the live manifest and manifest in the file. But we annotate the secret even if it's created without a manifest file.
The kubectl apply command writes the contents of the configuration file to the kubectl.kubernetes.io/last-applied-configuration annotation. This is used to identify fields that have been removed from the configuration file and need to be cleared from the live configuration.
so for example if we created secrets like
kubectl create secret generic test --from-literal=value1=xxxx
and now we want to patch this secrets with manifest file, we will get a warning "Warning: resource secrets/test is missing the kubectl.kubernetes.io/last-applied-configuration"
apiVersion: v1
data:
value1: eHh4eA==
kind: Secret
metadata:
name: test
namespace: playground-account-app
type: Opaque
and if we tried to apply this we will get warning
Warning: resource secrets/test is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
Avoid these warning:
The above warning is because of missing the annotation but we can annotate the object in the Kubernetes to fix and avoid these warning
kubectl annotate secret test --overwrite kubectl.kubernetes.io/last-applied-configuration='{"apiVersion":"v1","data":{"value1":"eHh4eA=="},"kind":"Secret","metadata":{"annotations":{},"name":"test","namespace":"namespace-name"},"type":"Opaque"}'
CodePudding user response:
...is there away you can add this annotation information
Try append --save-config
to the command:
kubectl create secret generic --from-literal=value1=xxxx ... --save-config