简体   繁体   English

是否可以在Kubernetes中启动自签名Docker注册表并将其他服务用作该注册表来获取其映像?

[英]Is it possible to start Self-Signed Docker Registry in Kubernetes and have other service use that as the registry to get its image?

Problem Statement 问题陈述

  • I want to deliver a private registry which all the images I need for my product bundled in them ( Yes, It will be fat image, but I am fine with that) 我想提供一个私人注册表,将我的产品所需的所有图像捆绑在其中(是的,这将是胖图像,但是我可以接受)
  • I would manually upload this image in some way 我会以某种方式手动上传此图像
  • I would run the docker private registry as a service in Kubernetes (probably in some namespace) 我将在kubernetes中(可能在某些命名空间中)将docker私有注册表作为服务运行
  • When other services/deployments (in the same namespace as registry) happen in Kubernetes, they should refer to this registry using a consistent name 当Kubernetes中发生其他服务/部署(与注册表位于相同的名称空间)时,它们应使用一致的名称引用此注册表

Constraints 约束条件

  • We want registry to be exposed only to the cluster and not outside 我们希望注册表仅公开给集群,而不公开给集群
  • We want to use self signed certificate and not signed by CA 我们要使用自签名证书,而不是由CA签名

I followed some instructions from these links (do not know whether it was a right thing to do) 我遵循了这些链接中的一些说明(不知道这样做是否正确)

Create a certificate signed through Kubernetes 创建通过Kubernetes签名的证书

  1. Create a server.key 创建一个server.key

  2. Create a csr.info 创建一个csr.info

[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[ dn ]
C = US
ST = oh
L = cincinnati
O = engg
OU = prod
CN = prateek.svc.cluster.local

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = registry.prateek.svc.cluster.local

[ v3_ext ]
authorityKeyIdentifier=keyid,issuer:always
basicConstraints=CA:FALSE
keyUsage=keyEncipherment,dataEncipherment
extendedKeyUsage=serverAuth,clientAuth
subjectAltName=@alt_names
  1. Created the server.csr (openssl req -new -key server.key -out server.csr -config csr.conf) 创建了server.csr(openssl req -new -key server.key -out server.csr -config csr.conf)

  2. Create the CertificateSigningRequest in K8s 在K8s中创建CertificateSigningRequest

cat <<EOF | kubectl apply -f -
apiVersion: certificates.k8s.io/v1beta1
kind: CertificateSigningRequest
metadata:
name: registry.prateek
spec:
groups:
- system:authenticated
request: $(cat server.csr | base64 | tr -d '\n')
usages:
- digital signature
- key encipherment
- server auth
EOF
  1. Checked if the CSR exists 检查CSR是否存在
kubectl describe csr registry.prateek
Name: registry.prateek
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"certificates.k8s.io/v1beta1","kind":"CertificateSigningRequest","metadata":{"annotations":{},"name":"registry.prateek","namespace":""},"spec":{"groups":["system:authenticated"],"request":"LS0sdfsfsdsfd=","usages":["digital signature","key encipherment","server auth"]}}

CreationTimestamp: Thu, 11 Apr 2019 11:15:42 -0400
Requesting User: docker-for-desktop
Status: Pending
Subject:
Common Name: prateek.svc.cluster.local
Serial Number:
Organization: engg
Organizational Unit: prod
Country: US
Locality: cincinnati
Province: oh
Subject Alternative Names:
DNS Names: registry.prateek.svc.cluster.local
Events: <none>
  1. Approved the CSR : kubectl certificate approve registry.prateek 批准了CSR:kubectl证书批准了Registry.prateek

Start the registry internal service 启动注册表内部服务

  1. Added cert and key to the kind: Secret 对该类型添加了证书和密钥:秘密
registry-secret.yml 注册表秘密文件
apiVersion: apps/v1
kind: Deployment
metadata:
  name: registry
  namespace: prateek
  labels:
      app: registry
spec:
  replicas: 1
  selector:
    matchLabels:
      app: registry
  template:
    metadata:
      labels:
        app: registry
    spec:
      containers:
        - name: registry
          image: prateek/registry
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 443
          env:
            - name: REGISTRY_HTTP_ADDR
              value: "0.0.0.0:443"
            - name: REGISTRY_HTTP_TLS_CERTIFICATE
              value: "/certs/certificate"
            - name: REGISTRY_HTTP_TLS_KEY
              value: "/certs/key"
          volumeMounts:
            - name: cert-files
              mountPath: /certs
      volumes:
        - name: cert-files
          secret:
            secretName: registry-credentials
  1. Create registry deployment and service (using those secrets) registry-deployment.yml 创建注册表部署和服务(使用这些秘密)Registry-deployment.yml
apiVersion: v1
kind: Service
metadata:
  name: registry
  namespace: prateek
spec:
  selector:
    app: registry
  ports:
  - protocol: TCP
    port: 443
    targetPort: 443
  type: LoadBalancer

registry-service.yml 注册表服务

 apiVersion: v1 kind: Service metadata: name: registry namespace: prateek spec: selector: app: registry ports: - protocol: TCP port: 443 targetPort: 443 type: LoadBalancer 

Test regsitry service is up 测试注册服务已启动

  1. Tried to this the registry endpoint thru a test pod. 为此,注册表端点通过测试窗格进行了尝试。 I had image of this test pod loaded in docker already. 我已经在docker中加载了该测试容器的图像。
 curl https://registry.prateek.svc.cluster.local/v2/_catalog -k {"repositories":["prateek/echo"]} 

Deployment using image from the registry service 使用注册表服务中的映像进行部署

  1. Tried deployment with image: registry.prateek/prateek/echo:latest 尝试使用映像进行部署:registry.prateek / prateek / echo:latest
Normal Pulling 10s (x2 over 25s) kubelet, docker-for-desktop pulling image "registry.prateek/prateek/echo:latest"
Warning Failed 10s (x2 over 25s) kubelet, docker-for-desktop Failed to pull image "registry.prateek/prateek/echo:latest": rpc error: code = Unknown desc = Error response from daemon: Get https://registry.prateek/v2/: Service Unavailable 
  1. the deployment gives the error 部署出现错误
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
  namespace: cequence
  labels:
      app: hello
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello
        image: registry.prateek.svc.cluster.local/prateek/echo:latest
        imagePullPolicy: IfNotPresent
        ports:
         - containerPort: 5678
        args: ["-text=hello"]
  1. Changed deployment to have image: registry.prateek.svc.cluster.local/prateek/echo:latest 将部署更改为具有映像:registry.prateek.svc.cluster.local / prateek / echo:latest
Warning Failed 1s kubelet, docker-for-desktop Failed to pull image "registry.prateek.svc.cluster.local/prateek/echo:latest": rpc error: code = Unknown desc = Error response from daemon: Get https://registry.prateek.svc.cluster.local/v2/: Service Unavailable
  1. get the similar error 得到类似的错误
 Warning Failed 1s kubelet, docker-for-desktop Failed to pull image "registry.prateek.svc.cluster.local/prateek/echo:latest": rpc error: code = Unknown desc = Error response from daemon: Get https://registry.prateek.svc.cluster.local/v2/: Service Unavailable 

I do not that this is even possible. 我不认为这是可能的。 Run a docker registry as a service and point other service in the namespace to use that registry deployment in the cluster. 将Docker注册表作为服务运行,并在命名空间中指向其他服务以在群集中使用该注册表部署。 Any suggestion is welcome 欢迎任何建议

The container daemon is running outside of kubernetes. 容器守护程序正在kubernetes外部运行。

Therefore, if you want to pull the image, you need to make sure that the registry is reachable from the node directly, without using kubernetes mechanisms like a service. 因此,如果要提取映像,则需要确保可以直接从节点访问注册表,而无需使用诸如服务之类的kubernetes机制。 (Not like you tested it in step 9 through a pod, you must be able to work directly on the node!) (不像您在第9步中通过Pod测试的那样,您必须能够直接在节点上工作!)

The usual options are to create a DNS entry or hosts.txt entry to point to a node where either through a hostPort (container) or nodePort (service) the registry is accessible or you use an appropriate ingress. 通常的选择是创建一个DNS条目或hosts.txt条目,以指向一个节点,该节点可以通过hostPort (容器)或nodePort (服务)访问注册表,或者您使用适当的入口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker Swarm和自签名Docker Registry - Docker Swarm and self-signed Docker Registry CircleCI中的自签名Docker注册表 - Self-signed docker registry in CircleCI 不安全 Docker 注册表和自签名证书 - Insecure Docker registry and self-signed certificates 使用minikube从本地Docker注册表中提取映像(带有自签名CA证书) - Using minikube to pull image from local Docker registry (with self-signed CA certificate) 使用自签名证书配置本地注册表 - Configuring local registry with self-signed certificate azure kubernetes 服务 - 私有注册表上的自签名证书 - azure kubernetes service - self signed cert on private registry 如何使Drone Docker插件通过具有自签名TLS证书的自托管注册表进行身份验证 - How to make Drone Docker plugin to authenticate with a self-hosted registry having a self-signed TLS certificate 如何使用自签名证书通过TLS将Docker应用程序包推送到私有注册表 - How to push a Docker Application Package to private registry via TLS using a self-signed certificate 如何使用 Kubernetes 访问带有自签名证书的私有 Docker 注册表? - How do I access a private Docker registry with a self signed certificate using Kubernetes? (Kube.netes + Minikube) 无法从本地注册表获取 docker 图像 - (Kubernetes + Minikube) can't get docker image from local registry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM