我有以下 kubernetes 機密,并希望將所有內容原樣復制到單個檔案中。
api:
url: https://app.a.com/test
application:
metadata: name="myname"
在 yaml 我有以下
apiVersion: apps/v1
kind: Deployment
metadata:
name: active-mq
labels:
app: active-mq
spec:
replicas: 1
selector:
matchLabels:
app: active-mq
template:
metadata:
labels:
app: active-mq
spec:
containers:
- image: [name-of-my-image-from-docker-hub]
name: active-mq
imagePullPolicy: Always
resources:
requests:
memory: 500Mi
cpu: 200m
limits:
memory: 1000Mi
cpu: 400m
volumeMounts:
- name: active-creds
mountPath: /home/my.properties
subPath: my.properties
volumes:
- name: active-creds
secret:
secretName: creds
restartPolicy: Always
當我 bash 到容器時,我看到它my.properties在/home. 這是我在這里想念的東西嗎?我期待 my.properties 應該包含以下內容
api:
url: https://app.a.com/test
application:
metadata: name="myname"
uj5u.com熱心網友回復:
您的問題尚不清楚,但我懷疑沒有創建 Secret 來反映您需要的密鑰。在這種情況下,密鑰成為檔案名(即my.properties)。您不希望鍵是apiand application。
# Create the file locally
echo '
api:
url: https://app.a.com/test
application:
metadata: name="myname"' > my.foo
# Create the Kubernetes Secret from it
# NB This renames to "my.properties" from "my.foo"
kubectl create secret generic test \
--from-file=my.properties=${PWD}/my.foo
get secret test \
--output=yaml
產量:
apiVersion: v1
data:
my.properties: YXBpOiAK...
kind: Secret
metadata:
name: test
type: Opaque
NOTE
data包含一個鍵my.properties
然后:
# Using your Deployment
kubectl apply \
--filename=71484256.yaml
# I replaced your image with busybox
kubectl exec \
--stdin --tty \
deployment/test \
-- ash
然后從容器的外殼中:
# ls /home
my.properties
# more /home/my.properties
api:
url: https://app.a.com/test
application:
metadata: name=myname
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/444612.html
標籤:Kubernetes kubectl Kubernetes-秘密
上一篇:如何使UIActivityViewController基于動態陣列動態排除專案?
下一篇:在卷掛載目錄中找不到檔案
