0%

kubernetes container registry secret setup

pull private container registry from gitlab

  1. to your repo > setting > repository

  2. expand Deploy Token and set tokennam, username and scope

  3. click create deploy token

  4. then run:

    1
    kubectl create secret docker-registry <secrect_name> --docker-server=registry.gitlab.com --docker-username=<username> --docker-password=<gitlab_token> -n <namespace>
  1. in deployment or image spec:

    • add imagePullSecrets
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    spec:
    containers:
    - name: <arbitrary name>
    image: registry.gitlab.com/<username>/<container-registry-path>:<tag>
    imagePullPolicy: Always
    securityContext:
    privileged: false
    imagePullSecrets:
    - name: <secrect_name>
    restartPolicy: Always
    dnsPolicy: ClusterFirst
    nodeSelector: #this can be use to specify node
    kubernetes.io/hostname: <node-name>
    schedulerName: default-scheduler

pull private image from github registry (ghcr.io)

  1. apply a personal access token

  2. then run:

    1
    kubectl create secret docker-registry <secrect_name> --docker-server=ghcr.io --docker-username=<github-username> --docker-password=<personal-access-token> -n <namespace>
  3. in deployment or image spec:

    • add imagePullSecrets
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    spec:
    containers:
    - name: <arbitrary name>
    image: ghcr.io/<username>/<container-registry-path>:<tag>
    imagePullPolicy: Always
    securityContext:
    privileged: false
    imagePullSecrets:
    - name: <secrect_name>
    restartPolicy: Always
    dnsPolicy: ClusterFirst
    nodeSelector: #this can be use to specify node
    kubernetes.io/hostname: <node-name>
    schedulerName: default-scheduler