I followed some instructions from these links (do not know whether it was a right thing to do)
Create a server.key
Create a 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
Created the server.csr (openssl req -new -key server.key -out server.csr -config csr.conf)
Create the CertificateSigningRequest in K8s
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
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>
registry-secret.yml
apiVersion: v1
kind: Secret
metadata:
name: registry-credentials
data:
certificate: <CERTIFICATE in base64>
key: <KEY in base64>
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
apiVersion: v1
kind: Service
metadata:
name: registry
namespace: prateek
spec:
selector:
app: registry
ports:
- protocol: TCP
port: 443
targetPort: 443
type: LoadBalancer
curl https://registry.prateek.svc.cluster.local/v2/_catalog -k
{"repositories":["prateek/echo"]}
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/prateek/echo:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5678
args: ["-text=hello"]
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
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"]
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. Any suggestion is welcome
The container daemon is running outside of 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. (Not like you tested it in step 9 through a pod, you must be able to work directly on the node!)
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.