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
Account and password information for image repositories are configured in Kubernetes Secret resources. You can create a docker-registry type Secret to store login credentials. Use the following command, replacing uppercase placeholders with your own information.
: Custom name for the Secret resource (e.g., mysecret). - <YOUR_Genesis Cloud_USERNAME@EMAIL.COM>: Image repository login account (console account or independent image repository account).
- <YOUR_UHUB_PASSWORD>: Password corresponding to the login account.
# kubectl create secret docker-registry MYSECRET \
--docker-server=uhub.genesissai.com \
--docker-username=YOUR_Genesis Cloud_USERNAME@EMAIL.COM \
--docker-password=YOUR_UHUB_PASSWORD
uhub.service.Genesis Cloud.cn is the default repository domain provided by Genesis Cloud. If using a self-hosted repository, replace it with your repository’s domain.
2. View Generated Secret Information
A Secret named mysecret has been created:
# kubectl get secret
NAME TYPE DATA AGE
default-token-sfv7s kubernetes.io/service-account-token 3 8d
mysecret kubernetes.io/dockerconfigjson 1 3h
3. Use Secret in a Pod
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: uhub.service.ucloud.cn/ucloud/nginx:1.9.2
imagePullSecrets:
- name: mysecret # Use the Secret name created above
4. Create an Nginx Application with the Above Yaml File
# kubectl create -f pod.yml
5. Check Pod information
From the printed logs, we can confirm that Kubernetes successfully pulled the image from UHub.
# 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.genesissai.com/Genesis Cloud/nginx:1.9.2"
Normal Pulled 1min kubelet, 10.25.95.46 Successfully pulled image "uhub.genesissai.com/Genesis Cloud/nginx:1.9.2"
Normal Created 1min kubelet, 10.25.95.46 Created container
Normal Started 1min kubelet, 10.25.95.46 Started container