前提k8s中部署的jenkins
绑定卷
pod中 /var/jenkins_home
首先进入容器中
docker exec -it id bash
使用ssh-keygen -t rsa -C "xxx@example.com"
生成.ssh
cd ~/.ssh
可以看到两个文件
id_rsa id_rsa.pub
公钥id_rsa.pub配置到git服务器上
私钥配置到jenkins里面
如果此时你的git服务port不为22 那么会访问失败
此时需要在.ssh下创建 config文件
这里 在容器中是没有vi啥命令的,我是到宿主机上编辑的对应文件
通过命令
docker inspect dbbb418d777e|grep Mounts -A 30
可以查看到绑定的目录
{
"Type": "bind",
"Source": "/var/lib/kubelet/pods/5bc765c4-17e1-4ac3-9e00-ecdf5266b2db/volumes/kubernetes.io~local-volume/jenkins-pv-volume",
"Destination": "/var/jenkins_home",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
config中配置
# gitea
Host gitea.xxx.org
Port 3122
HostName gitea.xxx.org
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa在容器中
/var/jenkins_home 下新建一个temp目录,其它地方貌似也没有权限 git clone git@gitea.xxxxxx.org:xxxx/xxxxx-root.git 会有提示 输入yes就好了 同时.ssh下面会生成一个know_host文件 The authenticity of host '[gitea.xxxxx.org]:3122 ([192.168.0.51]:3122)' can't be established. ECDSA key fingerprint is SHA256:2v5oDfHnefXh9nO3ouoFM19ufCjmZFCqB8a2KHglKEo. Are you sure you want to continue connecting (yes/no/[fingerprint])? yu^H^[[3~ Please type 'yes', 'no' or the fingerprint: yes
乐享:知识积累,快乐无限。