Kubernetes使用Harbor仓库

来源:互联网 发布:plc网络传输器弊端 编辑:程序博客网 时间:2024/06/05 19:30

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.yamlapiVersion: v1kind: ReplicationControllermetadata:  name: frontend  namespace: common  labels:    name: frontendspec:  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)

0 0
原创粉丝点击