<p>Is it not possible to have a docker-registry running in kubernetes and then port-forward to and then use this registry when deploying?</p>

<pre><code>kubectl apply -f deploy-registry.yaml
</code></pre>

<p>and then<br></p>

<pre><code>kubectl port-forward docker-registry-vx 5000:5000
</code></pre>

Chris G.
<p>The reason that you're having trouble is that the kubelet agent running on the node where the pod is scheduled is what pulls the container image, not your workstation, and port-forwarding the registry to your local workstation does not provide this access.</p>

<p>In previous Kubernetes versions, there was to be a registry cluster addon, but that has been taken out of the mainline tree (though some distributions like <a href="https://microk8s.io/docs/registry" rel="nofollow noreferrer">Microk8s</a> and <a href="https://github.com/kubernetes/minikube/blob/master/docs/addons.md" rel="nofollow noreferrer">Minikube</a> have their own), so you will need to use a bit of elbow grease to get this working. I would caution, though, that using a registry external to the cluster, such as Google Container Registry (GKE), or even just a private Docker Hub repository is, generally, a much better design pattern for production use as it avoids things like circular dependencies and also removes the operational effort of keeping the registry running and secured.</p>

<p>In general, the steps are:</p>

<ol>
<li>Get the registry running. You can use the <a href="https://github.com/helm/charts/tree/master/stable/docker-registry" rel="nofollow noreferrer">docker-registry Helm chart</a>, for example.</li>
<li>Expose the registry to the host. This could be as a ClusterIP, NodePort service, via Host Networking, or, if you have an appropriate CNI plugin, by simply exposing a host-routable IP address. The most "compatible" way to do this will be a ClusterIP service (i.e. this strategy will work on almost any cluster), but is also the most clunky as you will not be able to push images into it from outside of the cluster.</li>
<li>Refer to the registry by its "publicly" accessible address (i.e. the one that the node can use to connect) in the <code>image</code> field on the Pod/Deployment spec.</li>
<li>If required, use an <a href="https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/" rel="nofollow noreferrer">ImagePullSecret</a> to provide credentials to pull the private image with.</li>
</ol>

<p>A related question can be found here: <a href="https://stackoverflow.com/questions/52675900/kubernetes-pull-images-from-internal-registry-with-on-premise-deployment">Kubernetes: Pull images from internal registry with on-premise deployment</a> and a reasonably comprehensive blog post can be found here: <a href="https://medium.com/@jmarhee/deploying-a-docker-registry-with-persistent-storage-and-local-only-access-on-your-kubernetes-1c6470d3611c" rel="nofollow noreferrer">https://medium.com/@jmarhee/deploying-a-docker-registry-with-persistent-storage-and-local-only-access-on-your-kubernetes-1c6470d3611c</a></p>
