• kubernetes创建的pod如何从私有镜像仓库拉取镜像


    kubernetes创建的pod默认会从国外拉取镜像,如何使k8s从指定的镜像仓库拉取镜像创建应用?

    一、创建secret

    命令行方式创建

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

    例如:

    kubectl -n k8s-ecoysystem-apps create secret docker-registry registry-key 
    --docker-server=registry.test.com 
    --docker-username=admin 
    --docker-password=admin123 
    --docker-email=12563478@qq.com

    yaml方式创建
    1.在docker服务器上登录镜像仓库

    [root@node ~]# docker login registry.test.com
    Username: admin
    Password:
    WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
    Configure a credential helper to remove this warning. See
    https://docs.docker.com/engine/reference/commandline/login/#credentials-store
    
    Login Succeeded

    2.base64加密/root/.docker/config.json

    # cat ~/.docker/config.json | base64

    3.编写yaml文件

    将上述步骤中经过base64加密的值拷贝到.dockerconfigjson键对应的值位置
    # cat
    myregistrykey.yaml apiVersion: v1 kind: Secret metadata: name: myregistrykey data: .dockerconfigjson: UmVhbGx5IHJlYWxseSByZWVlZWVlZWVlZWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGx5eXl5eXl5eXl5eXl5eXl5eXl5eSBsbGxsbGxsbGxsbGxsbG9vb29vb29vb29vb29vb29vb29vb29vb29vb25ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubmdnZ2dnZ2dnZ2dnZ2dnZ2dnZ2cgYXV0aCBrZXlzCg== type: kubernetes.io/dockerconfigjson

    4.创建secret

    # kubectl apply -f myregistrykey.yaml

    二、使用secret
    在部署文件中使用secret
    使用方式
    imagePullSecrets:
    - name: myregistrykey # secret名称
    例如:
    1.创建Pod资源

    # cat nginx-pod.yaml
    apiVersion: v1 kind: Pod metadata: name: tomcat spec: containers:
    - name: tomcat-c image: tomcat imagePullSecrets: - name: myregistrykey
    # kubectl apply -f nginx-pod.yaml

    2.创建Deployment

    # cat nginx-deploy.yaml
    apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: selector: matchLabels: app: nginx replicas: 2 template: metedata: name: nginx labels: app: nginx spec: imagePullSecrets: - name: myregistrykey containers: - name: nginx-c image: nginx imagePullPolicy: Always
    # kubectl apply -f nginx-deploy.yaml
  • 相关阅读:
    MJExtension使用
    使用html5结构化元素
    我的第一个html页面
    编写delegate(明天补充)
    iOS 获取系统相册数据(不是调系统的相册)
    CocoaLumberjack+XcodeColor(输出带有颜色的日志)在安装过程中遇到的问题
    iOS基础-UIKit框架-高级视图-UIPickerView-实例1:点菜(列与列之间无关系)
    iOS基础-UIKit框架-基础视图-UIScrollView
    OC与iOS开发
    Effective Objective-C 2.0 编写高质量iOS与OS X代码的52个有效方法---1-2章
  • 原文地址:https://www.cnblogs.com/golinux/p/11987862.html
Copyright © 2020-2023  润新知