当前位置:网站首页>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
边栏推荐
- QT reading and writing XML files
- Anonymous type (c Guide Basics)
- Flink SQL实现流批一体
- ansible自動化運維詳解(一)ansible的安裝部署、參數使用、清單管理、配置文件參數及用戶級ansible操作環境構建
- 一键清理项目下pycharm和Jupyter缓存文件
- Navicat remote connection MySQL
- jsp页面编码
- Excle plus watermark
- Record: JS several methods to delete one or more items in the array
- Idea: export Yapi interface using easyyapi plug-in
猜你喜欢

Detailed explanation of ansible automatic operation and maintenance (I) installation and deployment, parameter use, list management, configuration file parameters and user level ansible operating envi
![[explanation] get ora-12838: cannot read / modify an object after modifying it in parallel](/img/7c/0adc0940b6d5c8a61d34bfa5f66ee7.png)
[explanation] get ora-12838: cannot read / modify an object after modifying it in parallel

Qt编译QtXlsx库

vslam PPT

Excle plus watermark

AQS & ReentrantLock 实现原理

洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解

程序,进程,线程;内存结构图;线程的创建和启动;Thread的常用方法

freertos学习02-队列 stream buffer message buffer

Let the earth have less "carbon" and rest on the road
随机推荐
微信小程序 catchtap=“toDetail“ 事件问题
JS中复制数组
SYS_CONNECT_BY_PATH(column,'char') 结合 start with ... connect by prior
Detailed description of self feeling of auricular point weight loss 0422
Campus transfer second-hand market source code download
LINQ学习系列-----1.4 匿名对象
Introduction to protobuf
基于TCP/IP协议的网络通信实例——文件传输
Data deletion and modification (MySQL)
对OutputStream类的flush()方法的误解
5.6 综合案例-RTU-
Ajax cache prevention method
一键清理项目下pycharm和Jupyter缓存文件
QT compilation qtxlsx Library
LINQ Learning Series ----- 1.4 anonymous objects
DOM learning - add + - button
Comparison of indoor positioning technology
关于数组复制问题
洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
根据字节码获取类的绝对路径