Kubernetes Pod 鏡像拉取策略

Kubernetes Pod 鏡像拉取策略

官方文檔:https://kubernetes.io/docs/concepts/containers/images/nginx


• IfNotPresent:默認值,鏡像在宿主機上不存在時才拉取
• Always:每次建立 Pod 都會從新拉取一次鏡像
• Never: Pod 永遠不會主動拉取這個鏡像docker

 

# 查看已建立deployment的拉取策略
kubectl get deploy/nginx-deployment -o yaml | grep imagePull
imagePullPolicy: IfNotPresentjson

 

認證鏡像倉庫拉取方法

一、Node:修改須要認證的鏡像倉庫 vim

{"insecure-registries": ["須要認證的倉庫地址"]}
vim /etc/docker/daemon.json

二、Node:登陸鏡像倉庫(可提交項目鏡像到私有倉庫)api

docker login 鏡像倉庫IP地址

三、Node:查看倉庫docker認證信息、並編碼app

cat ~/.docker/config.json | base64 -w 0

四、Master:建立認證yaml文件、 .dockerconfigjson下就是Node config.json的編碼信息ide

apiVersion: v1
kind: Secret
metadata:
  # 拉取鏡像策略定義名稱
  name: registry-pull-secret
data:
  .dockerconfigjson: ewoJImF1dGhzIjkfldsajkfldsajklfsJKLFJDAKLJKljkJjfkldsjkfdsaJKLFDASLjkljfklJFKDLHASKjkjfLfdsjaklfjdsaklFDSAJKLFDJSAKLFDSAjklfjdsaklf;jdaklfj;dsklajfkldsajfkld;ajkfld==
type: kubernetes.io/dockerconfigjson
vim registry-pull-secret.yaml

下面根據條件完成策略編碼

apiVersion: v1
kind: Pod
metadata:
  name: foo
  namespace: awesomeapps
spec:
  containers:
    - name: foo
      image: janedoe/awesomeapp:v1
      imagePullPolicy: IfNotPresent
修改拉取策略類型
apiVersion: v1
kind: Pod
metadata:
  name: foo
  namespace: awesomeapps
spec:
  containers:
    - name: foo
      image: janedoe/awesomeapp:v1
  imagePullSecrets:
    - name: myregistrykey
進項拉取憑據配置
相關文章
相關標籤/搜索