- Related issues: #2176 [Enhancement] Air-gap operation: Support using a private registry for Rancher agent image
 
Category:
- Rancher Integration
 
Verification Steps
Environment Setup
- Use vagrant-pxe-harvester to create a harvester cluster.
 - Create another VM 
myregistryand set it in the same virtual network. - In 
myregistryVM:- Install docker.
 - Run following commands:
 
mkdir auth docker run \ --entrypoint htpasswd \ httpd:2 -Bbn testuser testpassword > auth/htpasswd mkdir -p certs openssl req \ -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key \ -addext "subjectAltName = DNS:myregistry.local" \ -x509 -days 365 -out certs/domain.crt sudo mkdir -p /etc/docker/certs.d/myregistry.local:5000 sudo cp certs/domain.crt /etc/docker/certs.d/myregistry.local:5000/domain.crt docker run -d \ -p 5000:5000 \ --restart=always \ --name registry \ -v "$(pwd)"/certs:/certs \ -v "$(pwd)"/registry:/var/lib/registry \ -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \ -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \ -v "$(pwd)"/auth:/auth \ -e "REGISTRY_AUTH=htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \ registry:2 - Set IP and domain in 
/etc/hoststo all VM (harvester andmyregistry). Remember to change the IP.# vim /etc/hosts 192.168.0.50 myregistry.local - Login, pull, and push nginx image in 
myregsitryVM:# username: testuser, password: testpassword docker login myregistry.local:5000 docker pull nginx:latest docker tag nginx:latest myregistry.local:5000:/nginx:latest docker push myregistry.local:5000/nginx:latest docker pull nginx:1.22 docker tag nginx:latest myregistry.local:5000:/nginx:1.22 docker push myregistry.local:5000/nginx:1.22 - Copy 
certs/domain.crtcontent inmyregistryVM and paste it toadditional-casetting. 
Test Plan 1
- 
Update the Harvester containerd-registry setting to use private registry

{ "Mirrors": { "docker.io": { "Endpoints": [ "https://myregistry.local:5000" ], "Rewrites": null } }, "Configs": { "myregistry.local:5000": { "Auth": null, "TLS": { "CAFile": "", "CertFile": "", "KeyFile": "", "InsecureSkipVerify": false } } }, "Auths": null } - 
Open K9s -> search -> secrets -> containerd -> y

 - 
Check content in cattle-system/harvester-containerd-registry secret is changed.

 - 
Search jobs -> containerd -> l -> tail
 - 
Check there are new jobs to auto apply the new containerd-registry setting.

 - 
Apply following yaml in file
apiVersion: apps/v1 kind: Deployment metadata: name: myregistry-nginx spec: selector: matchLabels: image: myregistry-nginx template: metadata: labels: image: myregistry-nginx spec: containers: - imagePullPolicy: Always image: myregistry.local:5000/nginx:latest name: nginx``` harvester-node-0:~ # kubectl apply -f deploy.yaml deployment.apps/myregistry-nginx created``` - 
search deployments -> default namespace -> myregsistry-nginx -> describe -> shift + g
 - 
Check the nginx can be deployed.
 
Test Plan 2
- Click the 
default valueto update the Harvester containerd-registry setting to default empty
 - In K9s
 - Check content in cattle-system/harvester-containerd-registry secret is changed.
 - Check there are new jobs to auto apply the new containerd-registry setting.
 - Search secrets -> containerd -> e
 - Clean registry.yaml data field
# Please edit the object below. Lines beginning with a '#' will be ignored, # and an empty file will abort the edit. If an error occurs while saving this file will be # reopened with the relevant failures. # apiVersion: v1 data: registries.yaml: "" kind: Secret metadata: creationTimestamp: "2022-10-04T08:51:47Z" name: harvester-containerd-registry namespace: cattle-system resourceVersion: "42088" uid: 8445547f-430a-474e-9783-dc6b16914eb7 type: Opaque - Search -> deployments -> find nginx-1.2.2
 - Check cannot pull nginx-1.2.2 image

 
Test Plan 3
- Add back the Harvester containerd-registry setting to use private registry again

 - Check content in cattle-system/harvester-containerd-registry secret is changed.

 - Check there are new jobs to auto apply the new containerd-registry setting.

 - Check nginx 1.22 deployment is automatically back to running.

 
Expected Results
- 
Update the Harvester containerd-registry setting with private registry, confirm can pull image and deploy nginx service correctly from private registry

 - 
Change the Harvester
containerd-registryto default value, the nginx 1.22 cannot be deployed since no private registry assigned.
 - 
Add back the the Harvester containerd-registry setting to private registry, confirm can pull image and deploy nginx service correctly from private registry
