当前位置:网站首页>Kubernetes如何使用harbor拉去私有镜像
Kubernetes如何使用harbor拉去私有镜像
2022-04-23 08:12:00 【MyySophia】
7. harbor 配合kubernetes使用
7.1 k8s拉取镜像的方式
Always:当容器失效时,由Kubelet自动重启该容器。RestartPolicy的默认值。
OnFailure:当容器终止运行且退出码不为0时由Kubelet重启。
Never:无论何种情况下,Kubelet都不会重启该容器。
注意,这里的重启是指在 Pod 所在 Node 上面本地重启,并不会调度到其他 Node 上去。
7.2使用私有镜像仓库拉去镜像
7.2.1 k8s-node节点添加验证
将harbor服务器上如下三个文件分发到kubernetes集群的node节点/etc/docker/certs.d/10.50.10.185/
的这目录
- 服务器证书(10.50.10.185.cert
)
密钥(10.50.10.185.key
)- CA文件(
ca.crt
)
7.2.2 拉去镜像
在node节点执行
docker pull 10.50.10.185/harbortest/nginx:latest
如果可以成功拉取代表node节点的证书已生效
7.2.3 创建一个 docker registry secret
使用私有仓库
kubectl create secret docker-registry regsecret --docker-server=https://10.50.10.185 --docker-username=admin --docker-password=Harb2323 --docker-email=[email protected]
使用 Azure Container Registry(ACR): https://kubernetes.feisky.xyz/concepts/objects/pod
ACR_NAME=dregistry
SERVICE_PRINCIPAL_NAME=acr-service-principal
# Populate the ACR login server and resource id.
ACR_LOGIN_SERVER=$(az acr show --name $ACR_NAME --query loginServer --output tsv)
ACR_REGISTRY_ID=$(az acr show --name $ACR_NAME --query id --output tsv)
# Create a contributor role assignment with a scope of the ACR resource.
SP_PASSWD=$(az ad sp create-for-rbac --name $SERVICE_PRINCIPAL_NAME --role Reader --scopes $ACR_REGISTRY_ID --query password --output tsv)
# Get the service principle client id.
CLIENT_ID=$(az ad sp show --id http://$SERVICE_PRINCIPAL_NAME --query appId --output tsv)
# Create secret
kubectl create secret docker-registry acr-auth --docker-server $ACR_LOGIN_SERVER --docker-username $CLIENT_ID --docker-password $SP_PASSWD --docker-email [email protected]
7.2.4 引用docker registry secret的两种方式
直接在pod中引用
apiVersion: v1
kind: Pod
metadata:
name: harbor-test
spec:
containers:
- name: harbor-test
image: 10.50.10.185/harbortest/nginx:latest
imagePullSecrets:
- name: regsecret
secret 添加到 service account 中 s并通过ervice account 引用
显然如果将secret添加到sa中,就又多了一层抽象,不用在每个pod或者deployment中的每个container都写一遍imagePullSecrets。而且向用户屏蔽了细节。用户不需要关心
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "regsecret"}]}'
/opt/k8s]#kubectl get sa -oyaml
apiVersion: v1
items:
- apiVersion: v1
imagePullSecrets:
- name: regsecret
kind: ServiceAccount
metadata:
creationTimestamp: "2022-03-18T12:31:44Z"
name: default
namespace: default
resourceVersion: "4202955"
uid: a9b88295-630e-4121-94e1-ab53a17f4f49
secrets:
- name: default-token-qvnrc
kind: List
metadata:
resourceVersion: ""
selfLink: ""
实战
使用deployment部署nginx
apiVersion: apps/v1
kind: Deployment
metadata:
name: harbor-test
labels:
app: nginx
spec:
replicas: 10
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
#image: nginx:latest
image: 10.50.10.185/harbortest/nginx:latest
ports:
- containerPort: 80
image字段一定要写harbor全路径,否则将使用默认的源拉去镜像
版权声明
本文为[MyySophia]所创,转载请带上原文链接,感谢
https://blog.csdn.net/MyySophia/article/details/124350805
边栏推荐
- SYS_CONNECT_BY_PATH(column,'char') 结合 start with ... connect by prior
- JS common array methods
- 396. Rotate Function
- 基于TCP/IP协议的网络通信实例——文件传输
- Record: JS several methods to delete one or more items in the array
- swagger文档导出自定义v2/api-docs拦截
- There are some problems when using numeric type to query string type fields in MySQL
- 洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
- synchronized 锁的基本用法
- LINQ Learning Series ----- 1.4 anonymous objects
猜你喜欢
正点原子携手OneOS直播 OneOS系统教程全面上线
vslam PPT
CGM optimizes blood glucose monitoring and management -- Yiyu technology appears in Sichuan International Medical Exchange Promotion Association
Failed to convert a NumPy array to a Tensor(Unsupported Object type int)
AQS & ReentrantLock 实现原理
Talk about the basic but not simple stock data
RPC过程
Knowledge points and problem solutions related to information collection
Qt编译QtXlsx库
测试你的机器学习流水线
随机推荐
K210学习笔记(二) K210与STM32进行串口通信
npm安装yarn
Add random attributes to the Li class array objects and sort them
STM32F103ZET6【标准库函数开发】----库函数介绍
匿名類型(C# 指南 基礎知識)
There are some problems when using numeric type to query string type fields in MySQL
信息收集相关知识点及题解
Ansible Automation Operation and Maintenance details (ⅰ) Installation and Deployment, Parameter use, list Management, Profile Parameters and user level ansible operating environment Construction
freertos学习02-队列 stream buffer message buffer
JSP page coding
微信小程序 catchtap=“toDetail“ 事件问题
Search the complete navigation program source code
vslam PPT
JVM工具之Arthas使用
根据字节码获取类的绝对路径
AQS & ReentrantLock 实现原理
Protobuf简介
Shell script advanced
面了一圈,整理了这套面试题。。
什么是RPC