【问题标题】:Accessing Nexus repository manager password in a kubernetes pod在 kubernetes pod 中访问 Nexus 存储库管理器密码
【发布时间】:2021-10-24 19:52:58
【问题描述】:

我已经使用 helm chart 在我的 Kubernetes 集群中安装了 Sonatype nexus repository manager

我正在使用Kyma 安装。

Nexus 存储库管理器已正确安装,我可以访问该应用程序。

但登录密码文件似乎在附加在 pod 中的 pv 卷声明 /nexus-data 中。

现在每当我尝试使用 kubectl exec 命令访问 pod 时:

kubectl exec -i -t $POD_NAME -n dev -- /bin/sh

我收到以下错误:

OCI runtime exec failed: exec failed: container_linux.go:367: starting container process caused: exec: "/bin/sh": stat /bin/sh: no such file or directory: unknown

我了解此问题是因为该图像不提供外壳功能。 有没有其他方法可以访问 pvc 中的密码文件?

【问题讨论】:

标签: kubernetes kubectl nexus3


【解决方案1】:

您可以尝试kubectl cp command,但可能无法正常工作,因为容器内没有外壳。

您无法真正在 Kubernetes 中直接访问 pvc 使用的 pv,但有一个简单的解决方法 - 只需创建另一个挂载 pvc 的 pod(带有外壳)并访问它。为避免出现Volume is already used by pod(s) / node(s) 之类的错误,我建议将此 pod 安排在与 nexus pod 相同的节点上。

  1. 检查您的 nexus pod 所在的节点:NODE=$(kubectl get pod <your-nexus-pod-name> -o jsonpath='{.spec.nodeName}')
  2. 为节点设置nexus标签:kubectl label node $NODE nexus=here(避免使用“yes”或“true”而不是“here”;Kubernetes will read it as boolean, not as the string)
  3. 通过运行kubectl describe pod <your-nexus-pod-name> 将您的nexus pvc 名称安装到pod 上
  4. 从上一步创建简单的 pod 定义裁判到 nexus pvc
apiVersion: v1
kind: Pod
metadata:
  name: access-nexus-data
spec:
  containers:
    - name: access-nexus-data-container
      image: busybox:latest
      command: ["sleep", "999999"]
      volumeMounts:
        - name: nexus-data
          mountPath: /nexus-data
          readOnly: true
  volumes:
    - name: nexus-data
      persistentVolumeClaim:
        claimName: <your-pvc-name>
  nodeSelector:
    nexus: here
  1. 使用kubectl exec access-nexus-data -it -- sh 访问pod 并读取数据。您也可以使用前面提到的kubectl cp 命令。

如果您使用的是某些云提供的 Kubernetes 解决方案,您可以尝试将 pvc 使用的 pv 卷挂载到托管在云上的 VM。

来源:similar Stackoverflow topic

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 2021-02-14
    • 2012-05-19
    相关资源
    最近更新 更多