K8S使用阿里雲鏡像倉庫


1. Node使用docker login阿里雲的私有倉庫,保證調度過來pod時可以及時拉取到鏡像
    docker login --username=xxx@hotmail.com registry.cn-hangzhou.aliyuncs.com

2. 需要在master上生成secret秘鑰

kubectl create secret docker-registry alidockerregistryssecret --docker-server=registry.cn-hangzhou.aliyuncs.com --docker-username=xxx --docker-password=xxx --docker-email=xxxx@xxx.com

說明:
alidockerregistryssecret :指定秘鑰的鍵名稱,可自行定義
--docker-server :指定docker倉庫的地址
--docker-username :指定docker倉庫賬號
--docker-password :指定docker倉庫密碼
--docker-email: 指定docker郵件地址(選填)

alidockerregistryssecret 只能在默認namespace下使用,其他要使用則在創建時指定namespace(-n xxx)

 

3.將ImagePullSecrets添加到default
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "alidockerregistryssecret"}]}'

4. deployment,並執行kubectl create -f alidocker.yml

 

apiVersion: apps/v1
kind: Deployment
metadata:
    name: centos-test
    labels:
        app: centos-test
spec:
    replicas: 2
    selector:
        matchLabels:
            app: centos-test
    template:
        metadata:
            labels:
                app: centos-test
        spec:
            serviceAccountName: default
            imagePullSecrets:
                - name: alidockerregistryssecret
            containers:
                - name: centos-test
                  image: registry.cn-hangzhou.aliyuncs.com/mj_ns/centos7:jre-slim
                  imagePullPolicy: IfNotPresent
                  command: ["/bin/bash"]
                  args: ["-c", "while true; do echo 'Hello World'; sleep 10;done"]
                  ports:
                      - containerPort: 80

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM