When installing Ubuntu and Debian operating systems, by setting up a mirror site in the local area network, the installation process of apt software package can be greatly accelerated, while reducing the burden of the main server.
Here we share the method of establishing apt image service based on Kubernetes.
- For the apt image service container used, see https://github.com/openthings/apt-mirror-http-server
- For the script files used in this article, see https://github.com/openthings/kubernetes-tools/apt-mirror
Deploy to Kubernetes. The configuration file is as follows:
apiVersion: v1 kind: ServiceAccount metadata: name: apt-mirror namespace: apt-mirror --- kind: Service apiVersion: v1 metadata: name: apt-mirror namespace: apt-mirror labels: app: apt-mirror spec: ports: - name: mirror-server port: 80 type: LoadBalancer selector: app: apt-mirror --- kind: Deployment apiVersion: apps/v1 metadata: name: apt-mirror namespace: apt-mirror spec: selector: matchLabels: app: apt-mirror replicas: 1 strategy: type: Recreate template: metadata: labels: app: apt-mirror spec: serviceAccount: apt-mirror containers: - name: apt-mirror image: seterrychen/apt-mirror-http-server ports: - name: mirror-server containerPort: 80 securityContext: capabilities: add: - DAC_READ_SEARCH - SYS_RESOURCE env: - name: RESYNC_PERIOD value: 12h imagePullPolicy: "IfNotPresent" volumeMounts: - name: mirror-volume mountPath: /var/spool/apt-mirror volumes: - name: mirror-volume hostPath: path: /home/supermap/apt-mirror
We created a Deployment and a Service. The storage uses hostpath, just for the convenience of verifying the feasibility. In the production system, volumes can use NFS or other network distributed storage systems, so that they can be migrated, scaled and fault-tolerant.
Save the above file as mirror-server.sh and run:
kubectl create ns apt-mirror kubectl apply -f mirror-server.yaml
You can install the service into the apt mirror namespace.
Then, access the address listed in the service in the browser. It can be obtained by the following command:
kubectl get svc -n apt-mirror
If there is a problem with the image download, you can try to download it separately, as follows:
docker pull seterrychen/apt-mirror-http-server