git - Kubernetes 中的 Gitsync 未正确部署
问题描述
我在 kubernetes 中运行 gitsync 容器并尝试从 github 同步存储库。我已经使用 known_hosts 和 ssh 创建了秘密。但是我面临以下错误。
"msg"="failed to sync repo, aborting" "error"="error running command: exit status 128: "Cloning into '/tmp/git'...\nfatal: 无法从远程存储库读取。\n\ n请确保您具有正确的访问权限\n并且存储库存在。\n""
这是我的部署文件。
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitsync-deployment
labels:
app: gitsync
spec:
replicas: 1
selector:
matchLabels:
app: gitsync
template:
metadata:
labels:
app: gitsync
spec:
containers:
- name: git-sync
image: k8s.gcr.io/git-sync:v3.1.5
# command: ["cat"]
# args: ["/etc/git-secret/ssh"]
imagePullPolicy: Always
volumeMounts:
- name: git-secret
mountPath: /etc/git-secret
env:
- name: GIT_SYNC_REPO
value: "git@github.com:username/test.git"
- name: GIT_SYNC_SSH
value: "true"
- name: GIT_SYNC_BRANCH
value: master
- name: GIT_SYNC_DEST
value: git
- name: GIT_SYNC_DEPTH
value: "1"
volumes:
- name: html
emptyDir: {}
- name: git-secret
secret:
secretName: git-creds
defaultMode: 256
解决方案
似乎您遵循了官方文档。
但事实证明,该文档根本没有提到将公钥放在哪里。
实际上,通过 SSH 进行 git 身份验证需要以下步骤:
1. 生成 SSH 密钥对:
ssh-keygen -t rsa -N "" -f mykey
此 cmd 生成 2 个文件:
- 私钥:
./mykey
- 公钥:
./mykey.pub
2. 将公钥放入您的 Github 帐户下的 Settings > SSH Keys
复制内容./mykey.pub
并将其添加到您的 github 帐户中。
3.将私钥放入k8s secret中
官方文档从这里开始,它被认为$HOME/.ssh/id_rsa
是私钥。
kubectl create secret generic git-creds \
--from-file=ssh=./mykey \
....
其余的应该和官方文档解释的一样。
推荐阅读
- flutter - 如何防止颤动的showBottomSheet被向下拖动解除?
- c# - String a = "" AND String b = " " 不是一回事吗?
- kubernetes - 指标尚不可用指标-AWS 上的 kubernetes
- javascript - 即使用户错过了 .,- 等特殊字符,也可以搜索特定的产品详细信息
- apache-spark - 如何在连接中组合 MapType 列
- python - 运行python脚本时如何检查磁盘空间?
- python - DNI 计算的天顶角
- javascript - 如何在“
- python - 如何处理 2 个小部件事件来控制数据框?
- node.js - firebase 功能中的承诺问题