Skip to Content
Image RepositoryUsing UHub in UK8S

Using UHub in UK8S

This article mainly explains how to create applications using UHub or your own private container image in UK8S.

Kubernetes supports specifying secrets for Pods to pull images from private repositories. Below we demonstrate how to use it to create an Nginx application by pulling an image from UHub;

1. Generate Secret Key

Use the following command to create a secret. Note to replace the uppercase values with your own information. MYSECRET is the key value of the secret which you can define by yourself;

# kubectl create secret docker-registry MYSECRET \ --docker-server=uhub.ucloud-global.com \ --docker-username=YOUR_UCLOUD_USERNAME@EMAIL.COM \ --docker-password=YOUR_UHUB_PASSWORD

2. Check the generated secret key information, we can see a secret named mysecret has been generated;

# kubectl get secret NAME TYPE DATA AGE default-token-sfv7s kubernetes.io/service-account-token 3 8d mysecret kubernetes.io/dockerconfigjson 1 3h

3. Add Secret to the Pod Sample

apiVersion: v1 kind: Pod metadata: name: nginx labels: app: nginx spec: containers: - name: nginx image: uhub.ucloud-global.com/ucloud/nginx:1.9.2 imagePullSecrets: - name: mysecret

4. Create an Nginx application with the above yaml file

# kubectl create -f pod.yml

5. Check the Pod status, notice the printed logs, we can see that Kubernetes successfully pulled the image from UHub instead of DockerHub.

# kubectl describe pods/nginx ..... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 1min default-scheduler Successfully assigned default/nginx to 10.25.95.46 Normal Pulling 1min kubelet, 10.25.95.46 pulling image "uhub.ucloud-global.com/ucloud/nginx:1.9.2" Normal Pulled 1min kubelet, 10.25.95.46 Successfully pulled image "uhub.ucloud-global.com/ucloud/nginx:1.9.2" Normal Created 1min kubelet, 10.25.95.46 Created container Normal Started 1min kubelet, 10.25.95.46 Started container