有推荐的使用Kubernetes Secrets的方法吗?它们可以作为环境变量或使用卷安装公开。一个比另一个更安全吗?
environment-variables kubernetes docker-volume kubernetes-security kubernetes-secrets
我想使用 helm charts 在 kubernetes 中进行一些部署。这是我使用的示例覆盖值 yaml:
imageRepository: ""
ocbb:
imagePullPolicy: IfNotPresent
TZ: UTC
logDir: /oms_logs
tnsAdmin: /oms/ora_k8
LOG_LEVEL: 3
wallet:
client:
server:
root:
db:
deployment:
imageName: init_db
imageTag:
host: 192.168.88.80
port:
service:
alias:
schemauser: pincloud
schemapass:
schematablespace: pincloud
indextablespace: pincloudx
nls_lang: AMERICAN_AMERICA.AL32UTF8
charset: AL32UTF8
pipelineschemauser: ifwcloud
pipelineschemapass:
pipelineschematablespace: ifwcloud
pipelineindextablespace: ifwcloudx
pipelinealias:
queuename:
Run Code Online (Sandbox Code Playgroud)
在此文件中,我必须设置一些涉及凭据的值,例如 schemapass、pipelineschemapass...文档说明我必须生成 kubernetes 机密才能执行此操作,并将此密钥添加到具有相同路径层次结构的 yaml 文件中。
我生成了一些 kubernetes 的秘密,例如:
kubectl create secret generic schemapass --from-literal=password='pincloud'
Run Code Online (Sandbox Code Playgroud)
现在我不知道如何在我的 yaml 文件中引用这个新生成的秘密。关于如何在 yaml 图表中设置 schemapass 字段以引用 kubernetes 秘密的任何提示?
如何从秘密挂载“单个”文件?
我创建了一个秘密:
kubectl create secret generic oauth \
--from-file=./.work-in-progress/oauth_private.key \
--from-file=./.work-in-progress/oauth_public.key \
Run Code Online (Sandbox Code Playgroud)
如何将oauth_private.key文件作为单个文件挂载,而不是使用仅包含两个文件的目录覆盖整个路径(并可能删除最初存在于容器上的文件)?
我有一个像这样的配置图
apiVersion: v1
kind: ConfigMap
metadata:
namespace: develop
name: test-config
data:
app.conf: |
connection conn1
address 127.0.0.1:8080
user cluster1
password: <HERE COPY PASS FROM SECRET>
Run Code Online (Sandbox Code Playgroud)
app.conf 部分作为配置文件安装在容器内,使用
spec:
replicas: 1
...
spec:
containers:
- name: container-name
...
volumeMounts:
- name: test-config-vol
mountPath: /etc/app/app.conf
subPath: app.conf
volumes:
- name: test-config-vol
configMap:
name: test-config
Run Code Online (Sandbox Code Playgroud)
读取该文件的应用程序无法读取环境变量,并且我无法更改该行为,它是第三方应用程序。
我想知道如何在 Pod 部署期间将密码从秘密注入到密码字段中
我正在尝试从私人注册表中提取图像。但 pod 的状态是“ImagePullBackOff”,这意味着我需要向 pod 添加一个 Secret。
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Pulling 52m (x255 over 22h) kubelet, cn-huhehaote.i-hp3fkfzlcf1u9cigq2h7 pulling image "xxx/fcp"
Normal BackOff 8m (x5597 over 22h) kubelet, cn-huhehaote.i-hp3fkfzlcf1u9cigq2h7 Back-off pulling image "xxx/fcp"
Warning Failed 3m (x5618 over 22h) kubelet, cn-huhehaote.i-hp3fkfzlcf1u9cigq2h7 Error: ImagePullBackOff
Run Code Online (Sandbox Code Playgroud)
所以我在 pod yaml 中添加了以下代码。
spec:
containers:
- name: private-reg-container
image: <your-private-image>
imagePullSecrets:
- name: my-secret
Run Code Online (Sandbox Code Playgroud)
然后我得到了
error: map: map[] does not contain declared merge key: name
Run Code Online (Sandbox Code Playgroud)
我找到的解决方案是删除“imagePullSecret”,这对我不起作用。我想知道如何修复该错误。谁能帮我?
kubectl 版本是
kubectl …Run Code Online (Sandbox Code Playgroud) 在我的掌舵图上,我有一份工作pre-install,我需要使用我的秘密中的属性。但是,当我尝试安装 Helm Chart 时,我的pre-install工作出现以下错误:
错误:未找到机密“SecretsFileName”
在 pods 执行之前没有创建秘密?这里有什么问题?我该如何解决这个问题?
笔记:
"helm.sh/hook": pre-install,post-delete和"helm.sh/hook-weight": "1","helm.sh/hook-weight": "2"但问题仍然存在。我的预安装工作:
apiVersion: batch/v1
kind: Job
metadata:
name: "MyPodName"
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
#some more code
spec:
template:
#some more code
spec:
dnsPolicy: {{ .Values.specPolicy.dnsPolicy }}
restartPolicy: {{ .Values.specPolicy.restartPolicy }}
volumes:
- name: {{ .Values.volume.name }}
persistentVolumeClaim:
claimName: {{ .Values.volume.claimName }}
securityContext:
{{- toYaml .Values.securityContext | …Run Code Online (Sandbox Code Playgroud) --from-file使用文件名以外的文件名时,有没有办法设置 kubernetes 密钥名称?
secrets.json我在容器中使用了一堆不同的配置文件。但是,为了组织我的文件,它们都没有secrets.json在我的主机上命名。例如secrets.dev.json或secrets.test.json. 我的应用程序只知道读入secrets.json.
当我使用 创建秘密时kubectl create secret generic my-app-secrets --from-file=secrets.dev.json,这会导致密钥名称为secrets.dev.json,而不是secrets.json。
我将我的秘密内容作为文件安装(这是从 Docker swarm 迁移而来的遗留物)。
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-deployment
spec:
template:
spec:
volumes:
- name: my-secret
secret:
secretName: my-app-secrets
containers:
- name: my-app
volumeMounts:
- name: my-secret
mountPath: "/run/secrets/secrets.json"
subPath: "secrets.json"
Run Code Online (Sandbox Code Playgroud)
因为它secrets.json不作为键存在,因为它使用了文件名 ( secrets.dev.json),所以它最终会变成一个目录。我最终得到了这个安装路径:/run/secrets/secrets.json/secrets.dev.json。
我希望能够将密钥名称设置为secrets.json而不是使用secrets.dev.json.
有谁知道在什么情况下选择 Kubernetes 秘密而不是 google 秘密管理器,反之亦然?两者有何区别?
google-cloud-platform google-kubernetes-engine kubernetes-secrets google-secret-manager
我正在使用一个kubernetes ConfigMap,其中包含一个应用程序的数据库配置,并且有一个包含数据库密码的秘密。我需要在ConfigMap中使用此密钥,因此当我尝试在ConfigMap中添加环境变量并从密钥中指定pod部署中的值时,由于ConfigMap中的值占用了密码,因此我无法使用密码连接到mysql变量的确切字符串。
apiVersion: v1
kind: ConfigMap
metadata:
name: config
data:
APP_CONFIG: |
port: 8080
databases:
default:
connector: mysql
host: "mysql"
port: "3306"
user: "root"
password: "$DB_PASSWORD"
Run Code Online (Sandbox Code Playgroud)
和deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: app
labels:
app: backend
spec:
replicas: 1
template:
metadata:
labels:
app: backend
spec:
containers:
- name: app
image: simple-app-image
ports:
- name: "8080"
containerPort: 8080
env:
- name: APP_CONFIG
valueFrom:
configMapKeyRef:
name: config
key: APP_CONFIG
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: "mysql-secret"
key: "mysql-root-password"
Run Code Online (Sandbox Code Playgroud)
注意:秘密存在,我能够获取“ mysql-root-password”值并用于登录数据库
我创建了一个这样的秘密:
kubectl create secret generic test --from-literal=username=testuser --from-literal=password=12345
Run Code Online (Sandbox Code Playgroud)
我想将用户名更新为,testuser2但我只想使用kubectl patch --type='json'.
这就是我尝试这样做的方式:
kubectl patch secret test --type='json' -p='[{"data":{"username": "testuser 2"}}]' -v=1
Run Code Online (Sandbox Code Playgroud)
但我收到了:
“”无效
请记住,我想使用 选项来执行此操作--type='json',没有其他解决方法。