Merge pull request #1548 from catherineluse/private-registries

Add detail about deploying workloads using a private registry with Rancher UI and kubectl
This commit is contained in:
Denise
2019-07-01 19:53:32 -04:00
committed by GitHub
2 changed files with 87 additions and 7 deletions
@@ -4,10 +4,16 @@ weight: 3063
aliases:
- /rancher/v2.x/en/tasks/projects/add-registries/
---
Registries are Kubernetes secrets containing credentials used to authenticate with [private Docker registries](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/).
Registries are secrets containing credentials used to authenticate with [private registries](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/). Deployments use these secrets to authenticate with a private registry and then pull a Docker image hosted on it.
The word "registry" can mean two things, depending on whether it is used to refer to a Docker or Kubernetes registry:
Currently, credentials are pulled automatically only if the workload is created in the Rancher UI and not when it is created via kubectl.
- A **Docker registry** contains Docker images that you can pull in order to use them in your deployment. The registry is a stateless, scalable server side application that stores and lets you distribute Docker images.
- The **Kubernetes registry** is a secret that your deployment uses to authenticate with a Docker registry.
Deployments use the Kubernetes registry secret to authenticate with a private Docker registry and then pull a Docker image hosted on it.
Currently, deployments pull the private registry credentials automatically only if the workload is created in the Rancher UI and not when it is created via kubectl.
>**Prerequisites:** You must have a [private registry](https://docs.docker.com/registry/deploying/) available to use.
@@ -21,14 +27,87 @@ Currently, credentials are pulled automatically only if the workload is created
1. Select a **Scope** for the registry. You can either make the registry available for the entire project or a single [namespace]({{< baseurl >}}/rancher/v2.x/en/k8s-in-rancher/projects-and-namespaces/#namespaces).
1. Select the website that hosts your private registry. Then enter credentials that authenticate with the registry.
1. Select the website that hosts your private registry. Then enter credentials that authenticate with the registry. For example, if you use DockerHub, provide your DockerHub username and password.
1. Click **Save**.
**Result:** Your secret is added to the project or namespace, depending on the scope you chose. You can view the secret in the Rancher UI from the **Resources > Registries** view.
**Result:**
## What's Next?
- Your secret is added to the project or namespace, depending on the scope you chose.
- You can view the secret in the Rancher UI from the **Resources > Registries** view.
- Any workload that you create in the Rancher UI will have the credentials to access the registry if the workload is within the registry's scope.
Now that you have a registry added to the project or namespace, you can add it to a workload that's deploying an image from your private registry.
## Using a Private Registry
For more information on adding a registry to a workload, see [Deploying Workloads]({{< baseurl >}}/rancher/v2.x/en/k8s-in-rancher/workloads/deploy-workloads/).
You can deploy a workload with an image from a private registry through the Rancher UI, or with `kubectl`.
### Using the Private Registry with the Rancher UI
To deploy a workload with an image from your private registry,
1. Go to the project view,
1. Go to the **Workloads** tab.
1. Click **Deploy.**
1. Enter a unique name for the workload and choose a namespace.
1. In the **Docker Image** field, enter the URL of the path to the Docker image in your private registry. For example, if your private registry is on Quay.io, you could use `quay.io/<Quay profile name>/<Image name>`.
1. Click **Launch.**
**Result:** Your deployment should launch, authenticate using the private registry credentials you added in the Rancher UI, and pull the Docker image that you specified.
### Using the Private Registry with kubectl
When you create the workload using `kubectl`, you need to configure the pod so that its YAML has the path to the image in the private registry. You also have to create and reference the registry secret because the pod only automatically gets access to the private registry credentials if it is created in the Rancher UI.
The secret has to be created in the same namespace where the workload gets deployed.
Below is an example `pod.yml` for a workload that uses an image from a private registry. In this example, the pod uses an image from Quay.io, and the .yml specifies the path to the image. The pod authenticates with the registry using credentials stored in a Kubernetes secret called `testquay`, which is specified in `spec.imagePullSecrets` in the `name` field:
```
apiVersion: v1
kind: Pod
metadata:
name: private-reg
spec:
containers:
- name: private-reg-container
image: quay.io/<Quay profile name>/<image name>
imagePullSecrets:
- name: testquay
```
In this example, the secret named `testquay` is in the default namespace.
You can use `kubectl` to create the secret with the private registry credentials. This command creates the secret named `testquay`:
```
kubectl create secret docker-registry testquay \
--docker-server=quay.io \
--docker-username=<Profile name> \
--docker-password=<password>
```
To see how the secret is stored in Kubernetes, you can use this command:
```
kubectl get secret testquay --output="jsonpath={.data.\.dockerconfigjson}" | base64 --decode
```
The result looks like this:
```
{"auths":{"quay.io":{"username":"<Profile name>","password":"<password>","auth":"c291bXlhbGo6dGVzdGFiYzEyMw=="}}}
```
After the workload is deployed, you can check if the image was pulled successfully:
```
kubectl get events
```
The result should look like this:
```
14s Normal Scheduled Pod Successfully assigned default/private-reg2 to minikube
11s Normal Pulling Pod pulling image "quay.io/<Profile name>/<image name>"
10s Normal Pulled Pod Successfully pulled image "quay.io/<Profile name>/<image name>"
```
For more information, refer to the Kubernetes documentation on [creating a pod that uses your secret.](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret)
+1
View File
@@ -0,0 +1 @@
fun