k8s 拉取私有镜像,及拉取策略

 

[root@k8s-master1 configmap]# cat  wenruo_crm_v4.nfs.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: wenruo-crm
  name: wenruo-crm
  namespace: edu
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wenruo-crm
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: wenruo-crm
    spec:
      imagePullSecrets:
      - name: registry-pull-secret
      containers:
        - name: wenruo-crm
        # image: 10.1.234.11/library/wenruo-crm:v2
          image: 10.1.234.11/data/nginx:latest
          imagePullPolicy: Always
          ports:
          - containerPort: 80
          volumeMounts:
          - name: www
            mountPath: /usr/share/nginx/html

          - name: nginx-config
            mountPath: /etc/nginx/nginx.conf
            subPath: nginx.conf

      volumes:
        - name: www
          persistentVolumeClaim:
            claimName: wenruo-crm-pvc 
        - name: nginx-config
          configMap:
            name: nginx-config
            items:
            - key: nginx.conf
              path: nginx.conf
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wenruo-crm-pvc
  namespace: edu
spec:
  storageClassName: managed-nfs-storage    #名称应该与class  metadata 名称一样
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
 
---
apiVersion: v1
kind: Service
metadata:
  name: wenruo-crm
  namespace: edu
spec:
  type: ClusterIP
  selector:
    app: wenruo-crm 
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
 
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: wenruo-crm 
  namespace: edu
spec:
  rules:
  - host: wenruo-crm.rpdns.com
    http:
      paths:
      - path: /
        backend:
          serviceName: wenruo-crm 
          servicePort: 80

k8s 登陆仓库拉取代码的凭证

kubectl create secret docker-registry registry-pull-secret --docker-server=10.1.234.11 --docker-username=admin --docker-password=Harbor12345 --docker-email=admin@ctnrs.com -n edu

添加拉取凭证 

 imagePullSecrets:
      - name: registry-pull-secret

镜像拉取策略

imagePullPolicy: Always

IfNotPresent:默认值,镜像在宿主机上不存在时才拉取。

Always:每次创建Pod都会重新拉取一次镜像,可以保证都是最新版本镜像。

Never:Pod 永远不会主动拉取这个镜像

 


 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值