Setup edge cluster local image registry for K3s
Note: Skip this section if using remote image registry.
Procedure
Create the K3s image registry service:
a. Set
USE_EDGE_CLUSTER_REGISTRYenvironment variable totrue. This env indicatesagent-install.shscript to use local image registry:export USE_EDGE_CLUSTER_REGISTRY=trueb. Download the configuration file for the persistent volume claim from the server:
curl -sSLO https://raw.githubusercontent.com/open-horizon/open-horizon.github.io/master/docs/installing/k3s-persistent-claim.yamlc. Create the persistent volume claim:
kubectl apply -f k3s-persistent-claim.yamld. Verify that the persistent volume claim was created and it is in โPendingโ status:
kubectl get pvce. Create a file called k3s-registry-deployment.yaml with this content:
apiVersion: apps/v1 kind: Deployment metadata: name: docker-registry labels: app: docker-registry spec: replicas: 1 selector: matchLabels: app: docker-registry template: metadata: labels: app: docker-registry spec: volumes: - name: registry-pvc-storage persistentVolumeClaim: claimName: docker-registry-pvc containers: - name: docker-registry image: registry ports: - containerPort: 5000 volumeMounts: - name: registry-pvc-storage mountPath: /var/lib/registry --- apiVersion: v1 kind: Service metadata: name: docker-registry-service spec: selector: app: docker-registry type: NodePort ports: - protocol: TCP port: 5000Or download it from the server:
curl -sSLO https://raw.githubusercontent.com/open-horizon/open-horizon.github.io/master/docs/installing/k3s-registry-deployment.yamlf. Create the registry deployment and service:
kubectl apply -f k3s-registry-deployment.yamlg. Verify that the service was created:
kubectl get deployment kubectl get serviceh. Define the registry endpoint:
export REGISTRY_ENDPOINT=$(kubectl get service docker-registry-service | grep docker-registry-service | awk '{print $3;}'):5000 cat << EOF >> /etc/rancher/k3s/registries.yaml mirrors: "$REGISTRY_ENDPOINT": endpoint: - "http://$REGISTRY_ENDPOINT" EOFi. Restart K3s to pick up the change to /etc/rancher/k3s/registries.yaml:
systemctl restart k3sDefine this registry to Docker as an insecure registry:
a. Install Docker (if not already installed,
docker --versionto check):curl -fsSL get.docker.com | shb. Create or add to /etc/docker/daemon.json (replacing
<registry-endpoint>with the value of the$REGISTRY_ENDPOINTenvironment variable you obtained in a previous step):{ "insecure-registries": [ "<registry-endpoint>" ] }c. Restart Docker to pick up the change:
systemctl restart dockerd. Install
jq:apt-get -y install jq