2016-12-09 64 views
3

我在macOS 10.12上使用minikube並嘗試使用在碼頭中心託管的私人圖像。我知道minikube啓動一個虛擬機,據我所知,它將是我本地kubernetes集羣的唯一節點,並將託管我所有的pod。使用minikube從碼頭中心拉私人圖像

我讀到我可以通過運行eval $(minikube docker-env)來使用虛擬機的docker運行時。所以我使用這些變量從本地Docker運行時更改爲另一個。正在運行docker images我可以看到變更已經完成。

我的下一步就是使用docker login然後手工拉我的形象泊塢窗樞紐,這沒有錯誤結束登錄。之後,我認爲圖像將隨時被羣集中的任何羣組使用,但我總是得到ImagePullBackOff。我也嘗試通過minikube ssh ssh進入虛擬機,結果是一樣的,圖像是在那裏使用,但由於某種原因,我不知道它拒絕使用它。

萬一有幫助,這是我的部署描述文件:

apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    name: web-deployment 
spec: 
    replicas: 1 
template: 
    metadata: 
    labels: 
     app: nginx 
    spec: 
    containers: 
    - name: nginx 
     image: godraude/nginx 
     imagePullPolicy: Always 
     ports: 
     - containerPort: 80 
     - containerPort: 443 

這是kubectl describe pod <podname>輸出:

Events: 
    FirstSeen LastSeen Count From   SubobjectPath  Type  Reason  Message 
    --------- -------- ----- ----   -------------  -------- ------  ------- 
    1m  1m  1 {default-scheduler }    Normal  Scheduled Successfully assigned web-deployment-2451628605-vtbl8 to minikube 
    1m  23s  4 {kubelet minikube} spec.containers{nginx} Normal  Pulling  pulling image "godraude/nginx" 
    1m  20s  4 {kubelet minikube} spec.containers{nginx} Warning  Failed  Failed to pull image "godraude/nginx": Error: image godraude/nginx not found 
    1m  20s  4 {kubelet minikube}    Warning  FailedSync Error syncing pod, skipping: failed to "StartContainer" for "nginx" with ErrImagePull: "Error: image godraude/nginx not found" 

    1m 4s 5 {kubelet minikube} spec.containers{nginx} Normal BackOff  Back-off pulling image "godraude/nginx" 
    1m 4s 5 {kubelet minikube}    Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "nginx" with ImagePullBackOff: "Back-off pulling image \"godraude/nginx\"" 

回答

1

的問題是圖像拉動政策。它被設置爲Always,所以即使Docker存在,Docker也試圖拉取圖像。設置imagePullPolicy: Never解決了這個問題。

0

我覺得你需要的是建立一個祕密,這將告訴KUBE從那裏可以拉你的私人形象及其憑據

kubectl create secret docker-registry my-secret --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL 

以下命令列出分泌

kubectl get secret 
NAME   TYPE      DATA  AGE 
my-secret kubernetes.io/dockercfg 1   100d 

現在在部署認定中的u需要定義whcih祕密使用

apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    name: web-deployment 
spec: 
    replicas: 1 
template: 
    metadata: 
    labels: 
     app: nginx 
    spec: 
    containers: 
    - name: nginx 
     image: godraude/nginx 
     imagePullPolicy: Always 
     ports: 
     - containerPort: 80 
     - containerPort: 443 
    imagePullSecrets: 
     - name: my-secret 
相關問題