Kubernetes使用Harbor仓库

1.创建Secret:

kubectl create secret docker-registry SECRET_NAME –namespace=NAME_SPACE \
–docker-server=DOCKER_REGISTRY_SERVER –docker-username=DOCKER_USER \
–docker-password=DOCKER_PASSWORD –docker-email=DOCKER_EMAIL

其中,
docker-server 为通过docker login登陆时输入的地址
docker-username 为登陆时的账号
docker-password 为登陆时的密码
docker-email 为注册的账号时的邮箱地址

查看secret的内容:
kubectl get secret harbor –namespace=common -o yaml

2.在RC中引用:

root@kubernetes1:~/test# cat frontend-controller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: frontend
  namespace: common
  labels:
    name: frontend
spec:
  replicas: 3
  selector:
    name: frontend
  template:
    metadata:
      namespace: common
      labels:
        name: frontend
    spec:
      containers:
      - name: frontend
        image: server.com/test/guestbook-php-frontend
        env:
        - name: GET_HOSTS_FROM
          value: env
        ports:
        - containerPort: 80
      imagePullSecrets:
      - name: harbor

kubectl create -f frontend-controller.yaml

3.查看Pods状态及日志:

kubectl get pods –namespace=common
kubectl describe pod frontend-cwfsm –namespace=common

遇到的问题:

1.FailedSync Error syncing pod, skipping: failed to “StartContainer” for “frontend” with ErrImagePull: “Error response from daemon: {\”message\”:\”Get https://server.com/v1/_ping: dial tcp: lookup harbor.itopka.com on 10.16.40.3:53: no such host\”}”

解决:在公网解析了域名的私网IP地址。

2.FailedSync Error syncing pod, skipping: failed to “StartContainer” for “frontend” with ErrImagePull: “Error response from daemon: {\”message\”:\”Get https://server.com/v1/_ping: dial tcp 192.168.1.132:443: getsockopt: connection refused\”}”

解决:在/etc/default/docker中添加:
DOCKER_OPTS=”- -insecure-registry server.com”

ubuntu 15\16:
vim /lib/systemd/system/docker.service
ExecStart=/usr/bin/docker daemon -H fd:// –insecure-registry harbor.itopka.com



另外通过创建serviceAccount并引用的方式没有将pod运行起来,好不知道原因。提示:
Failed to pull image “server.com/test/guestbook-php-frontend”: image pull failed for server.com/test/guestbook-php-frontend:latest, this may be because there are no credentials on this request. details: (Error: image test/guestbook-php-frontend:latest not found)

posted @   忱康  阅读(107)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示