ToB企服应用市场:ToB评测及商务社交产业平台

标题: kubernetes之镜像拉取策略; [打印本页]

作者: 冬雨财经    时间: 2022-9-16 17:20
标题: kubernetes之镜像拉取策略;
  1. root@ks-master01-10:~# kubectl explain pod.spec.containers.imagePullPolicy
  2. KIND:     Pod
  3. VERSION:  v1
  4. FIELD:    imagePullPolicy <string>
  5. DESCRIPTION:
  6.      Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always
  7.      if :latest tag is specified, or IfNotPresent otherwise. Cannot be updated.
  8.      More info:
  9.      https://kubernetes.io/docs/concepts/containers/images#updating-images
复制代码
  1. root@ks-master01-10:~#  cat tomcat-test.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5.   name: tomcat-test
  6.   namespace: default
  7. spec:
  8.   containers:
  9.   - name: tomcat
  10.     image: tomcat:latest
  11.     imagePullPolicy: Always
  12. root@ks-master01-10:~# kubectl apply -f tomcat-test.yaml
  13. pod/tomcat-test created
复制代码
  1. root@ks-master01-10:~# kubectl get pods
  2. NAME                          READY   STATUS    RESTARTS      AGE
  3. tomcat-test                   1/1     Running   0             87s
复制代码
  1. root@ks-master01-10:~# kubectl describe pods tomcat-test
  2. Events:
  3.   Type    Reason     Age   From               Message
  4.   ----    ------     ----  ----               -------
  5.   Normal  Scheduled  82s   default-scheduler  Successfully assigned default/mysql-test to ks-node24-24
  6.   Normal  Pulling    81s   kubelet            Pulling image "tomcat:latest"
  7.   Normal  Pulled     45s   kubelet            Successfully pulled image "tomcat:latest" in 36.41152006s
  8.   Normal  Created    45s   kubelet            Created container tomcat
  9.   Normal  Started    45s   kubelet            Started container tomcat
复制代码

  1. root@ks-master01-10:~# cat httpdpod-test.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5.   name: httpd-testpod
  6.   namespace: default
  7. spec:
  8.   containers:
  9.   - name: httpd
  10.     image: registry.cn-hangzhou.aliyuncs.com/lengyuye/httpd:alpine3.14
  11.     imagePullPolicy: IfNotPresent
  12. root@ks-master01-10:~# kubectl apply -f httpdpod-test.yaml
  13. pod/httpd-testpod created
复制代码
来查看下详情;
为什么能拉取私有仓库的镜像,因为docker login认证过。没有认证的话拉取镜像的时候会Error;
  1. root@ks-master01-10:~# kubectl describe pods httpd-testpod
  2. Events:
  3.   Type    Reason     Age    From               Message
  4.   ----    ------     ----   ----               -------
  5.   Normal  Scheduled  4m28s  default-scheduler  Successfully assigned default/httpd-testpod to ks-node24-24
  6.   Normal  Pulling    4m27s  kubelet            Pulling image "registry.cn-hangzhou.aliyuncs.com/lengyuye/httpd:alpine3.14"
  7.   Normal  Pulled     4m24s  kubelet            Successfully pulled image "registry.cn-hangzhou.aliyuncs.com/lengyuye/httpd:alpine3.14" in 3.56652979s
  8.   Normal  Created    4m23s  kubelet            Created container httpd
  9.   Normal  Started    4m23s  kubelet            Started container httpd
复制代码
Pod运行正常;
  1. root@ks-master01-10:~# kubectl get pods
  2. NAME                          READY   STATUS    RESTARTS     AGE
  3. httpd-testpod                 1/1     Running   0            3m26s
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4