kubernete private registry doesn't work

2020-07-13 08:37发布

I configure kubernete private registry as per the following link: https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/registry, the only differences is the namespace change from kube-system to default.

a Docker registry

apiVersion: v1
kind: ReplicationController
metadata:
  name: kube-registry-v0
  namespace: default
  labels:
    k8s-app: kube-registry
    version: v0
    kubernetes.io/cluster-service: "true"
spec:
  replicas: 1
  selector:
    k8s-app: kube-registry
    version: v0
  template:
    metadata:
      labels:
        k8s-app: kube-registry
        version: v0
        kubernetes.io/cluster-service: "true"
    spec:
      containers:
      - name: registry
        image: registry:2
        resources:
          limits:
            cpu: 100m
            memory: 100Mi
        env:
        - name: REGISTRY_HTTP_ADDR
          value: :5000
        - name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY
          value: /var/lib/registry
        volumeMounts:
        - name: image-store
          mountPath: /var/lib/registry
        ports:
        - containerPort: 5000
          name: registry
          protocol: TCP
      volumes:
      - name: image-store
        nfs:
        # Use real NFS server address here.
          server: 172.19.180.4
        # Use real NFS server export directory.
          path: "/nfs/www"

registry Service yaml file:

apiVersion: v1
kind: Service
metadata:
  name: kube-registry
  namespace: default
  labels:
    k8s-app: kube-registry
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "KubeRegistry"
spec:
  selector:
    k8s-app: kube-registry
  ports:
  - name: registry
    port: 5000
    protocol: TCP`

Expose the registry on each node

`apiVersion: v1
kind: Pod
metadata:
  name: kube-registry-proxy
  namespace: default
spec:
  containers:
  - name: kube-registry-proxy
    image: gcr.io/google_containers/kube-registry-proxy:0.3
    resources:
      limits:
        cpu: 100m
        memory: 50Mi
    env:
    - name: REGISTRY_HOST
      value: kube-registry.kube-system.svc.cluster.local
    - name: REGISTRY_PORT
      value: "5000"
    - name: FORWARD_PORT
      value: "5000"
    ports:
    - name: registry
      containerPort: 5000
      hostPort: 5000`

the following is the result the correspond with that

root@fed-master ~]# kubectl get services
NAME            CLUSTER_IP     EXTERNAL_IP   PORT(S)         SELECTOR                AGE
dns-backend     10.18.110.23   <none>        8000/TCP        name=dns-backend        6d
kube-dns        10.18.0.10     <none>        53/UDP,53/TCP   k8s-app=kube-dns        3d
kube-registry   10.18.85.239   <none>        5000/TCP        k8s-app=kube-registry   2d
kubernetes      10.18.0.1      <none>        443/TCP         <none>                  26d
[root@fed-master ~]# kubectl get rc
CONTROLLER         CONTAINER(S)   IMAGE(S)                                         SELECTOR                           REPLICAS   AGE
kube-dns-v9        etcd           gcr.io/google_containers/etcd:2.0.9              k8s-app=kube-dns,version=v9        1          3d
                   kube2sky       gcr.io/google_containers/kube2sky:1.11                                              
                   skydns         gcr.io/google_containers/skydns:2015-03-11-001                                      
                   healthz        gcr.io/google_containers/exechealthz:1.0                                            
kube-registry-v0   registry       registry:2                                       k8s-app=kube-registry,version=v0   1         2d
[root@fed-master ~]# kubectl get pod
NAME                             READY     STATUS    RESTARTS   AGE
kube-dns-v9-uuee0                4/4       Running   0          3d
kube-registry-proxy-fed-master   1/1       Running   0          1d
kube-registry-proxy-fed-node     1/1       Running   0          1d
kube-registry-proxy-fed-node2    1/1       Running   0          1d
kube-registry-v0-slqx3           1/1       Running   0          2d

but the test result is not what i expected curl localhost:5000 curl: (56) Recv failure: Connection reset by peer

how to resolve it and how to use the local private registry? thank in advance

0条回答
登录 后发表回答