| copyright |
|
||
|---|---|---|---|
| lastupdated | 2017-08-14 |
{:new_window: target="_blank"} {:shortdesc: .shortdesc} {:screen: .screen} {:pre: .pre} {:table: .aria-labeledby="caption"} {:codeblock: .codeblock} {:tip: .tip} {:download: .download}
Creating a {{site.data.keyword.registryshort_notm}} token for a {{site.data.keyword.Bluemix_notm}} Dedicated image registry
{: #cs_dedicated_tokens}
Create a non-expiring token to use an image registry with clusters that you used for single and scalable groups. {:shortdesc}
-
Log in to the {{site.data.keyword.Bluemix_short}} Dedicated environment.
bx login -a api.<dedicated_domain>{: pre}
-
Request an
oauth-tokenfor the current session and save it as a variable.OAUTH_TOKEN=`bx iam oauth-tokens | awk 'FNR == 2 {print $3 " " $4}'`{: pre}
-
Request the ID of the org for the current session and save it as a variable.
ORG_GUID=`bx iam org <org_name> --guid`{: pre}
-
Request a permanent registry token for the current session. Replace <dedicated_domain> with the domain for your {{site.data.keyword.Bluemix_notm}} Dedicated environment. This token grants access to the images in the current namespace.
curl -XPOST -H "Authorization: ${OAUTH_TOKEN}" -H "Organization: ${ORG_GUID}" https://registry.<dedicated_domain>/api/v1/tokens?permanent=true{: pre}
Output:
{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2MzdiM2Q4Yy1hMDg3LTVhZjktYTYzNi0xNmU3ZWZjNzA5NjciLCJpc3MiOiJyZWdpc3RyeS5jZnNkZWRpY2F0ZWQxLnVzLXNvdXRoLmJsdWVtaXgubmV0" }{: screen}
-
Verify the Kubernetes secret.
kubectl describe secrets{: pre}
You can use this secret to work with IBM {{site.data.keyword.Bluemix_notm}} Container Service.
-
Create the Kubernetes secret to store your token information.
kubectl --namespace <kubernetes_namespace> create secret docker-registry <secret_name> --docker-server=<registry_url> --docker-username=token --docker-password=<token_value> --docker-email=<docker_email>{: pre}
Table 1. Understanding this command's components -
Create a pod that references the imagePullSecret.
-
Open your preferred editor and create a pod configuration script that is named mypod.yaml.
-
Define the pod and the imagePullSecret that you want to use to access the registry. To use a private image from a namespace:
apiVersion: v1 kind: Pod metadata: name: <pod_name> spec: containers: - name: <container_name> image: registry.<dedicated_domain>/<my_namespace>/<my_image>:<tag> imagePullSecrets: - name: <secret_name>{: codeblock}
Table 2. Understanding the YAML file components -
Save your changes.
-
Create the deployment in your cluster.
kubectl apply -f mypod.yaml{: pre}
-
