[英]How to upload and download docker images using nexus registry/repository?
我能夠使用 jenkins 管道發布 Docker 映像,但不能從 nexus 中提取 docker 映像。我使用 kaniko 構建映像。
部署.yml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test-app
name: test-app
namespace: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: test-app
template:
metadata:
labels:
app: test-app
spec:
hostNetwork: false
containers:
- name: test-app
image: ip_adress/demo:0.1.0
imagePullPolicy: Always
resources:
limits: {}
imagePullSecrets:
- name: registrypullsecret
服務.yml
apiVersion: v1
kind: Service
metadata:
labels:
app: test-app
name: test-app-service
namespace: jenkins
spec:
ports:
- nodePort: 32225
port: 8081
protocol: TCP
targetPort: 8081
selector:
app: test-app
type: NodePort
Jenkins 流水線主腳本
stage ('Build Image'){
container('kaniko'){
script {
sh '''
/kaniko/executor --dockerfile `pwd`/Dockerfile --context `pwd` --destination="$ip_adress:8082/demo:0.1.0" --insecure --skip-tls-verify
'''
}
stage('Kubernetes Deployment'){
container('kubectl'){
withKubeConfig([credentialsId: 'kube-config', namespace:'jenkins']){
sh 'kubectl get pods'
sh 'kubectl apply -f deployment.yml'
sh 'kubectl apply -f service.yml'
}
我創建了一個 Spring boot Java 應用程序的 dockerfile。 我已使用 Jenkins 管道將圖像發送到 Nexus,但我無法部署它。
kubectl get pod -n jenkins
測試應用程序-... 0/1 ImagePullBackOff
kubectl describe pod test-app-.....
來自服務器的錯誤 (NotFound):pods“test-app-..”未找到
docker pull $ip_address:8081/repository/docker-releases/demo:0.1.0```
來自守護進程的錯誤響應:Get "https://$ip_adress/v2/": http:server gave HTTP response to HTTPS client
ip地址:私有ip地址
如何作為 http 發送?
首先嘗試編輯 /etc/containerd/config.toml 並像這樣添加注冊表 ip:port { "insecure-registries": ["172.16.4.93:5000"] }
如果仍然存在問題,請將您的 nexus 注冊表憑據添加到 yaml kubernetes 文件,如下面的鏈接https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
如果我們想使用私有注冊表來拉取 kubernetes 中的圖像,我們需要將注冊表端點和憑據配置為機密,並在 pod 部署配置中使用它。
注意:secrets 必須與 Pod 位於相同的命名空間中
參考這個k8 官方文檔了解更多關於在 Kubernetes 中配置私有注冊表的細節
在您的情況下,您使用的是秘密registrypullsecret 。 因此,請再檢查一次密碼是否正確配置。 如果沒有,請嘗試按照上述文檔進行操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.