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
复制代码

 

posted on   jmbkeyes  阅读(2600)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· Qt个人项目总结 —— MySQL数据库查询与断言

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示