Answers: <p>The error you are getting is from your Kubernetes cluster being unable to pull container image from GitLab.</p>
  <p>Providing a temporary credential to pull the containers as deploy time is not a great solution. For example, say your Kubernetes cluster needs to scale up by adding another node, the node will come up and try and pull the container, but the secret will be invalid so you won't be able to scale.</p>
  <p>I'd create a GitLab static deployment token which has permission to pull images from the GitLab registry: <a href="https://docs.gitlab.com/ee/user/project/deploy_tokens/#read-container-registry-images" rel="nofollow noreferrer">https://docs.gitlab.com/ee/user/project/deploy_tokens/#read-container-registry-images</a></p>
  <p>You need to provide this secret to Kubernetes, for that see this document: <a href="https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/</a></p>
  <p>This should allow you to just do a <code>helm install</code> or <code>helm upgrade</code> successfully.</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-07-21T09:19:40.200Z
Answers: 2021-07-21T09:19:40.200Z
Answers: Matthew Hodgkins
Body: <p>I have a kubernetes cluster with 1 master and 2 workers. All nodes have their IP address. Let's call them like this:</p>
  <ul>
  <li>master-0</li>
  <li>worker-0</li>
  <li>worker-1</li>
  </ul>
  <p>The network pod policy and all my nodes communication are setting up correctly, all works perfectly. If I specify this infrastructure, it's just to be more specific about my case.</p>
  <p>Using helm I have created a chart which deploy a basic nginx. It's a docker image that I build on my private gitlab registry.</p>
  <p>With the gitlab ci, I have created a job which used two functions:</p>
  <pre><code># Init helm client on k8s cluster for using helm with gitlab runner
  function init_helm() {
    docker login -u &quot;$CI_REGISTRY_USER&quot; -p &quot;$CI_REGISTRY_PASSWORD&quot; &quot;$CI_REGISTRY&quot;
    mkdir -p /etc/deploy
    echo ${kube_config} | base64 -d &gt; ${KUBECONFIG}
    kubectl config use-context ${K8S_CURRENT_CONTEXT}
    helm init --client-only
    helm repo add stable https://kubernetes-charts.storage.googleapis.com/
    helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
    helm repo update
  }
  
  # Deploy latest tagged image on k8s cluster
  function deploy_k8s_cluster() {
    echo &quot;Create and apply secret for docker gitlab runner access to gitlab private registry ...&quot;
    kubectl create secret -n &quot;$KUBERNETES_NAMESPACE_OVERWRITE&quot; \
      docker-registry gitlab-registry \
      --docker-server=&quot;https://registry.gitlab.com/v2/&quot; \
      --docker-username=&quot;${CI_DEPLOY_USER:-$CI_REGISTRY_USER}&quot; \
      --docker-password=&quot;${CI_DEPLOY_PASSWORD:-$CI_REGISTRY_PASSWORD}&quot; \
      --docker-email=&quot;$GITLAB_USER_EMAIL&quot; \
      -o yaml --dry-run | kubectl replace -n &quot;$KUBERNETES_NAMESPACE_OVERWRITE&quot; --force -f -
    echo &quot;Build helm dependancies in $CHART_TEMPLATE&quot;
    cd $CHART_TEMPLATE/
    helm dep build
    export DEPLOYS=&quot;$(helm ls | grep $PROJECT_NAME | wc -l)&quot;
    if [[ ${DEPLOYS}  -eq 0 ]]; then
      echo &quot;Creating the new chart ...&quot;
      helm install --name ${PROJECT_NAME} --namespace=${KUBERNETES_NAMESPACE_OVERWRITE} . -f values.yaml
    else
    echo &quot;Updating the chart ...&quot;
      helm upgrade ${PROJECT_NAME} --namespace=${KUBERNETES_NAMESPACE_OVERWRITE} . -f values.yaml
    fi
  } 
  </code></pre>
  <p>The first function allow the gitlabrunner to login with docker, init helm and kubectl. The second to deploy on the cluster my image.</p>
  <p>All the process works well, e-g my jobs are passed on the gitlab ci, no error occurred except for the deployment of the pod.</p>
  <p><strong>Indeed I have this error</strong>:</p>
  <pre><code>Failed to pull image &quot;registry.gitlab.com/path/to/repo/project/image:TAG_NUMBER&quot;: rpc error: code
  = Unknown desc = Error response from daemon: Get https://registry.gitlab.com/v2/path/to/repo/project/image/manifests/image:TAG_NUMBER: denied: access forbidden
  </code></pre>
  <p>To be more specific, I am using <a href="https://docs.gitlab.com/ee/install/kubernetes/gitlab_runner_chart.html#configuration" rel="nofollow noreferrer">gitlab-runner helm chart</a> and this the config of the chart:</p>
  <pre><code>## GitLab Runner Image
  ##
  ## By default it's using gitlab/gitlab-runner:alpine-v{VERSION}
  ## where {VERSION} is taken from Chart.yaml from appVersion field
  ##
  ## ref: https://hub.docker.com/r/gitlab/gitlab-runner/tags/
  ##
  # image: gitlab/gitlab-runner:alpine-v11.6.0
  
  ## Specify a imagePullPolicy
  ## 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
  ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
  ##
  imagePullPolicy: IfNotPresent
  
  ## The GitLab Server URL (with protocol) that want to register the runner against
  ## ref: https://docs.gitlab.com/runner/commands/README.html#gitlab-runner-register
  ##
  gitlabUrl: https://gitlab.com/
  
  ## The Registration Token for adding new Runners to the GitLab Server. This must
  ## be retrieved from your GitLab Instance.
  ## ref: https://docs.gitlab.com/ce/ci/runners/README.html#creating-and-registering-a-runner
  ##
  runnerRegistrationToken: &quot;&lt;token&gt;&quot;
  
  ## The Runner Token for adding new Runners to the GitLab Server. This must
  ## be retrieved from your GitLab Instance. It is token of already registered runner.
  ## ref: (we don't yet have docs for that, but we want to use existing token)
  ##
  # runnerToken: &quot;&quot;
  #
  ## Unregister all runners before termination
  ##
  ## Updating the runner's chart version or configuration will cause the runner container
  ## to be terminated and created again. This may cause your Gitlab instance to reference
  ## non-existant runners. Un-registering the runner before termination mitigates this issue.
  ## ref: https://docs.gitlab.com/runner/commands/README.html#gitlab-runner-unregister
  ##
  unregisterRunners: true
  
  ## Set the certsSecretName in order to pass custom certficates for GitLab Runner to use
  ## Provide resource name for a Kubernetes Secret Object in the same namespace,
  ## this is used to populate the /etc/gitlab-runner/certs directory
  ## ref: https://docs.gitlab.com/runner/configuration/tls-self-signed.html#supported-options-for-self-signed-certificates
  ##
  # certsSecretName:
  
  ## Configure the maximum number of concurrent jobs
  ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  ##
  concurrent: 10
  
  ## Defines in seconds how often to check GitLab for a new builds
  ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  ##
  checkInterval: 30
  
  ## Configure GitLab Runner's logging level. Available values are: debug, info, warn, error, fatal, panic
  ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  ##
  # logLevel:
  
  ## For RBAC support:
  rbac:
    create: true
  
    ## Run the gitlab-bastion container with the ability to deploy/manage containers of jobs
    ## cluster-wide or only within namespace
    clusterWideAccess: true
  
    ## Use the following Kubernetes Service Account name if RBAC is disabled in this Helm chart (see rbac.create)
    ##
    serviceAccountName: default
  
  ## Configure integrated Prometheus metrics exporter
  ## ref: https://docs.gitlab.com/runner/monitoring/#configuration-of-the-metrics-http-server
  metrics:
    enabled: true
  
  ## Configuration for the Pods that that the runner launches for each new job
  ##
  runners:
    ## Default container image to use for builds when none is specified
    ##
    image: ubuntu:16.04
  
    ## Specify one or more imagePullSecrets
    ##
    ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
    ##
    imagePullSecrets: [&quot;namespace-1&quot;, &quot;namespace-2&quot;, &quot;default&quot;]
  
    ## Specify the image pull policy: never, if-not-present, always. The cluster default will be used if not set.
    ##
    # imagePullPolicy: &quot;&quot;
  
    ## Specify whether the runner should be locked to a specific project: true, false. Defaults to true.
    ##
    # locked: true
  
    ## Specify the tags associated with the runner. Comma-separated list of tags.
    ##
    ## ref: https://docs.gitlab.com/ce/ci/runners/#using-tags
    ##
    tags: my-tag-1, my-tag-2&quot;
  
    ## Run all containers with the privileged flag enabled
    ## This will allow the docker:dind image to run if you need to run Docker
    ## commands. Please read the docs before turning this on:
    ## ref: https://docs.gitlab.com/runner/executors/kubernetes.html#using-docker-dind
    ##
    privileged: true
  
    ## The name of the secret containing runner-token and runner-registration-token
    # secret: gitlab-runner
  
    ## Namespace to run Kubernetes jobs in (defaults to the same namespace of this release)
    ##
    # namespace:
  
    # Regular expression to validate the contents of the namespace overwrite environment variable (documented following).
    # When empty, it disables the namespace overwrite feature
    namespace_overwrite_allowed: overrided-namespace-*
  
    ## Distributed runners caching
    ## ref: https://gitlab.com/gitlab-org/gitlab-runner/blob/master/docs/configuration/autoscale.md#distributed-runners-caching
    ##
    ## If you want to use s3 based distributing caching:
    ## First of all you need to uncomment General settings and S3 settings sections.
    ##
    ## Create a secret 's3access' containing 'accesskey' &amp; 'secretkey'
    ## ref: https://aws.amazon.com/blogs/security/wheres-my-secret-access-key/
    ##
    ## $ kubectl create secret generic s3access \
    ##   --from-literal=accesskey=&quot;YourAccessKey&quot; \
    ##   --from-literal=secretkey=&quot;YourSecretKey&quot;
    ## ref: https://kubernetes.io/docs/concepts/configuration/secret/
    ##
    ## If you want to use gcs based distributing caching:
    ## First of all you need to uncomment General settings and GCS settings sections.
    ##
    ## Access using credentials file:
    ## Create a secret 'google-application-credentials' containing your application credentials file.
    ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-cache-gcs-section
    ## You could configure
    ## $ kubectl create secret generic google-application-credentials \
    ##   --from-file=gcs-applicaton-credentials-file=./path-to-your-google-application-credentials-file.json
    ## ref: https://kubernetes.io/docs/concepts/configuration/secret/
    ##
    ## Access using access-id and private-key:
    ## Create a secret 'gcsaccess' containing 'gcs-access-id' &amp; 'gcs-private-key'.
    ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-cache-gcs-section
    ## You could configure
    ## $ kubectl create secret generic gcsaccess \
    ##   --from-literal=gcs-access-id=&quot;YourAccessID&quot; \
    ##   --from-literal=gcs-private-key=&quot;YourPrivateKey&quot;
    ## ref: https://kubernetes.io/docs/concepts/configuration/secret/
    cache: {}
      ## General settings
      # cacheType: s3
      # cachePath: &quot;cache&quot;
      # cacheShared: true
  
      ## S3 settings
      # s3ServerAddress: s3.amazonaws.com
      # s3BucketName:
      # s3BucketLocation:
      # s3CacheInsecure: false
      # secretName: s3access
  
      ## GCS settings
      # gcsBucketName:
      ## Use this line for access using access-id and private-key
      # secretName: gcsaccess
      ## Use this line for access using google-application-credentials file
      # secretName: google-application-credential
  
    ## Build Container specific configuration
    ##
    builds:
      # cpuLimit: 200m
      # memoryLimit: 256Mi
      cpuRequests: 100m
      memoryRequests: 128Mi
  
    ## Service Container specific configuration
    ##
    services:
      # cpuLimit: 200m
      # memoryLimit: 256Mi
      cpuRequests: 100m
      memoryRequests: 128Mi
  
    ## Helper Container specific configuration
    ##
    helpers:
      # cpuLimit: 200m
      # memoryLimit: 256Mi
      cpuRequests: 100m
      memoryRequests: 128Mi
      image: gitlab/gitlab-runner-helper:x86_64-latest
  
    ## Service Account to be used for runners
    ##
    # serviceAccountName:
  
    ## If Gitlab is not reachable through $CI_SERVER_URL
    ##
    # cloneUrl:
  
    ## Specify node labels for CI job pods assignment
    ## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
    ##
    nodeSelector: {}
      # gitlab: true
  
  ## Configure resource requests and limits
  ## ref: http://kubernetes.io/docs/user-guide/compute-resources/
  ##
  resources:
    # limits:
    #   memory: 256Mi
    #   cpu: 200m
    requests:
      memory: 128Mi
      cpu: 100m
  
  ## Affinity for pod assignment
  ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
  ##
  affinity: {}
  
  ## Node labels for pod assignment
  ## Ref: https://kubernetes.io/docs/user-guide/node-selection/
  ##
  nodeSelector: {}
    # Example: The gitlab runner manager should not run on spot instances so you can assign
    # them to the regular worker nodes only.
    # node-role.kubernetes.io/worker: &quot;true&quot;
  
  ## List of node taints to tolerate (requires Kubernetes &gt;= 1.6)
  ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
  ##
  tolerations: []
    # Example: Regular worker nodes may have a taint, thus you need to tolerate the taint
    # when you assign the gitlab runner manager with nodeSelector or affinity to the nodes.
    # - key: &quot;node-role.kubernetes.io/worker&quot;
    #   operator: &quot;Exists&quot;
  
  ## Configure environment variables that will be present when the registration command runs
  ## This provides further control over the registration process and the config.toml file
  ## ref: `gitlab-runner register --help`
  ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html
  ##
  envVars:
    - name: RUNNER_EXECUTOR
      value: kubernetes
  </code></pre>
  <p>As you can see, I created a <strong>secret</strong> on my ci job, no error occurred here too. In my chart, I declare this same secret (by his name) in <code>values.yaml</code> file, which allow <code>deployment.yaml</code> to use it.</p>
  <p>Notes:</p>
  <ul>
  <li><p>If it was the registry, e-g my image repository <code>registry.gitlab.com/path/to/repo/project/image:TAG_NUMBER</code> , I will get an error like my image does not exist or something like this. To be more precise, just notice that the var <strong>TAG_NUMBER</strong> is set in my jobs, and I recover the right value. So I don't think my problem comes from the image repository url.</p>
  </li>
  <li><p>I have tested my secret with a simple pod deployment. All works well with these credentials, the pod is ok (I have use the <code>kubectl create -f &lt;filename&gt;.yaml</code> command. I juste read this post about kubernetes and gitlab: <a href="https://docs.gitlab.com/ee/topics/autodevops/#private-project-support" rel="nofollow noreferrer">https://docs.gitlab.com/ee/topics/autodevops/#private-project-support</a>. Maybe it links with my issue.</p>
  </li>
  </ul>
  
Comments: CC BY-SA 4.0
Comments: 2019-02-04T20:51:39.387Z
Comments: CI credentials for the registry have a lifespan of few minutes usually (5 by default, I don't know for gitlab.com). Feel free to self answer explaining how you solved the problem and accept the answer after :)
Comments: Tensibai
Tags: <docker><kubernetes><gitlab><helm><gitlab-ci-runner>
Title: Access denied when pulling private registry image using helm with gitlab runner helm chart and ci job
UserDisplayName: french_dev
ThreadText: # Access denied when pulling private registry image using helm with gitlab runner helm chart and ci job
  
  (Asked by: username_0 on 2019-02-04)
  
  I have a kubernetes cluster with 1 master and 2 workers. All nodes have their IP address. Let's call them like this:
  
  * master-0
  * worker-0
  * worker-1
  
  The network pod policy and all my nodes communication are setting up correctly, all works perfectly. If I specify this infrastructure, it's just to be more specific about my case.
  
  Using helm I have created a chart which deploy a basic nginx. It's a docker image that I build on my private gitlab registry.
  
  With the gitlab ci, I have created a job which used two functions:
  
  ```
  # Init helm client on k8s cluster for using helm with gitlab runner
  function init_helm() {
    docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
    mkdir -p /etc/deploy
    echo ${kube_config} | base64 -d > ${KUBECONFIG}
    kubectl config use-context ${K8S_CURRENT_CONTEXT}
    helm init --client-only
    helm repo add stable https://kubernetes-charts.storage.googleapis.com/
    helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
    helm repo update
  }
  
  # Deploy latest tagged image on k8s cluster
  function deploy_k8s_cluster() {
    echo "Create and apply secret for docker gitlab runner access to gitlab private registry ..."
    kubectl create secret -n "$KUBERNETES_NAMESPACE_OVERWRITE" \
      docker-registry gitlab-registry \
      --docker-server="https://registry.gitlab.com/v2/" \
      --docker-username="${CI_DEPLOY_USER:-$CI_REGISTRY_USER}" \
      --docker-password="${CI_DEPLOY_PASSWORD:-$CI_REGISTRY_PASSWORD}" \
      --docker-email="$GITLAB_USER_EMAIL" \
      -o yaml --dry-run | kubectl replace -n "$KUBERNETES_NAMESPACE_OVERWRITE" --force -f -
    echo "Build helm dependancies in $CHART_TEMPLATE"
    cd $CHART_TEMPLATE/
    helm dep build
    export DEPLOYS="$(helm ls | grep $PROJECT_NAME | wc -l)"
    if [[ ${DEPLOYS}  -eq 0 ]]; then
      echo "Creating the new chart ..."
      helm install --name ${PROJECT_NAME} --namespace=${KUBERNETES_NAMESPACE_OVERWRITE} . -f values.yaml
    else
    echo "Updating the chart ..."
      helm upgrade ${PROJECT_NAME} --namespace=${KUBERNETES_NAMESPACE_OVERWRITE} . -f values.yaml
    fi
  } 
  
  ```
  
  The first function allow the gitlabrunner to login with docker, init helm and kubectl. The second to deploy on the cluster my image.
  
  All the process works well, e-g my jobs are passed on the gitlab ci, no error occurred except for the deployment of the pod.
  
  **Indeed I have this error**:
  
  ```
  Failed to pull image "registry.gitlab.com/path/to/repo/project/image:TAG_NUMBER": rpc error: code
  = Unknown desc = Error response from daemon: Get https://registry.gitlab.com/v2/path/to/repo/project/image/manifests/image:TAG_NUMBER: denied: access forbidden
  
  ```
  
  To be more specific, I am using [gitlab-runner helm chart](https://docs.gitlab.com/ee/install/kubernetes/gitlab_runner_chart.html#configuration) and this the config of the chart:
  
  ```
  ## GitLab Runner Image
  ##
  ## By default it's using gitlab/gitlab-runner:alpine-v{VERSION}
  ## where {VERSION} is taken from Chart.yaml from appVersion field
  ##
  ## ref: https://hub.docker.com/r/gitlab/gitlab-runner/tags/
  ##
  # image: gitlab/gitlab-runner:alpine-v11.6.0
  
  ## Specify a imagePullPolicy
  ## 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
  ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
  ##
  imagePullPolicy: IfNotPresent
  
  ## The GitLab Server URL (with protocol) that want to register the runner against
  ## ref: https://docs.gitlab.com/runner/commands/README.html#gitlab-runner-register
  ##
  gitlabUrl: https://gitlab.com/
  
  ## The Registration Token for adding new Runners to the GitLab Server. This must
  ## be retrieved from your GitLab Instance.
  ## ref: https://docs.gitlab.com/ce/ci/runners/README.html#creating-and-registering-a-runner
  ##
  runnerRegistrationToken: "<token>"
  
  ## The Runner Token for adding new Runners to the GitLab Server. This must
  ## be retrieved from your GitLab Instance. It is token of already registered runner.
  ## ref: (we don't yet have docs for that, but we want to use existing token)
  ##
  # runnerToken: ""
  #
  ## Unregister all runners before termination
  ##
  ## Updating the runner's chart version or configuration will cause the runner container
  ## to be terminated and created again. This may cause your Gitlab instance to reference
  ## non-existant runners. Un-registering the runner before termination mitigates this issue.
  ## ref: https://docs.gitlab.com/runner/commands/README.html#gitlab-runner-unregister
  ##
  unregisterRunners: true
  
  ## Set the certsSecretName in order to pass custom certficates for GitLab Runner to use
  ## Provide resource name for a Kubernetes Secret Object in the same namespace,
  ## this is used to populate the /etc/gitlab-runner/certs directory
  ## ref: https://docs.gitlab.com/runner/configuration/tls-self-signed.html#supported-options-for-self-signed-certificates
  ##
  # certsSecretName:
  
  ## Configure the maximum number of concurrent jobs
  ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  ##
  concurrent: 10
  
  ## Defines in seconds how often to check GitLab for a new builds
  ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  ##
  checkInterval: 30
  
  ## Configure GitLab Runner's logging level. Available values are: debug, info, warn, error, fatal, panic
  ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  ##
  # logLevel:
  
  ## For RBAC support:
  rbac:
    create: true
  
    ## Run the gitlab-bastion container with the ability to deploy/manage containers of jobs
    ## cluster-wide or only within namespace
    clusterWideAccess: true
  
    ## Use the following Kubernetes Service Account name if RBAC is disabled in this Helm chart (see rbac.create)
    ##
    serviceAccountName: default
  
  ## Configure integrated Prometheus metrics exporter
  ## ref: https://docs.gitlab.com/runner/monitoring/#configuration-of-the-metrics-http-server
  metrics:
    enabled: true
  
  ## Configuration for the Pods that that the runner launches for each new job
  ##
  runners:
    ## Default container image to use for builds when none is specified
    ##
    image: ubuntu:16.04
  
    ## Specify one or more imagePullSecrets
    ##
    ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
    ##
    imagePullSecrets: ["namespace-1", "namespace-2", "default"]
  
    ## Specify the image pull policy: never, if-not-present, always. The cluster default will be used if not set.
    ##
    # imagePullPolicy: ""
  
    ## Specify whether the runner should be locked to a specific project: true, false. Defaults to true.
    ##
    # locked: true
  
    ## Specify the tags associated with the runner. Comma-separated list of tags.
    ##
    ## ref: https://docs.gitlab.com/ce/ci/runners/#using-tags
    ##
    tags: my-tag-1, my-tag-2"
  
    ## Run all containers with the privileged flag enabled
    ## This will allow the docker:dind image to run if you need to run Docker
    ## commands. Please read the docs before turning this on:
    ## ref: https://docs.gitlab.com/runner/executors/kubernetes.html#using-docker-dind
    ##
    privileged: true
  
    ## The name of the secret containing runner-token and runner-registration-token
    # secret: gitlab-runner
  
    ## Namespace to run Kubernetes jobs in (defaults to the same namespace of this release)
    ##
    # namespace:
  
    # Regular expression to validate the contents of the namespace overwrite environment variable (documented following).
    # When empty, it disables the namespace overwrite feature
    namespace_overwrite_allowed: overrided-namespace-*
  
    ## Distributed runners caching
    ## ref: https://gitlab.com/gitlab-org/gitlab-runner/blob/master/docs/configuration/autoscale.md#distributed-runners-caching
    ##
    ## If you want to use s3 based distributing caching:
    ## First of all you need to uncomment General settings and S3 settings sections.
    ##
    ## Create a secret 's3access' containing 'accesskey' & 'secretkey'
    ## ref: https://aws.amazon.com/blogs/security/wheres-my-secret-access-key/
    ##
    ## $ kubectl create secret generic s3access \
    ##   --from-literal=accesskey="YourAccessKey" \
    ##   --from-literal=secretkey="YourSecretKey"
    ## ref: https://kubernetes.io/docs/concepts/configuration/secret/
    ##
    ## If you want to use gcs based distributing caching:
    ## First of all you need to uncomment General settings and GCS settings sections.
    ##
    ## Access using credentials file:
    ## Create a secret 'google-application-credentials' containing your application credentials file.
    ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-cache-gcs-section
    ## You could configure
    ## $ kubectl create secret generic google-application-credentials \
    ##   --from-file=gcs-applicaton-credentials-file=./path-to-your-google-application-credentials-file.json
    ## ref: https://kubernetes.io/docs/concepts/configuration/secret/
    ##
    ## Access using access-id and private-key:
    ## Create a secret 'gcsaccess' containing 'gcs-access-id' & 'gcs-private-key'.
    ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-cache-gcs-section
    ## You could configure
    ## $ kubectl create secret generic gcsaccess \
    ##   --from-literal=gcs-access-id="YourAccessID" \
    ##   --from-literal=gcs-private-key="YourPrivateKey"
    ## ref: https://kubernetes.io/docs/concepts/configuration/secret/
    cache: {}
      ## General settings
      # cacheType: s3
      # cachePath: "cache"
      # cacheShared: true
  
      ## S3 settings
      # s3ServerAddress: s3.amazonaws.com
      # s3BucketName:
      # s3BucketLocation:
      # s3CacheInsecure: false
      # secretName: s3access
  
      ## GCS settings
      # gcsBucketName:
      ## Use this line for access using access-id and private-key
      # secretName: gcsaccess
      ## Use this line for access using google-application-credentials file
      # secretName: google-application-credential
  
    ## Build Container specific configuration
    ##
    builds:
      # cpuLimit: 200m
      # memoryLimit: 256Mi
      cpuRequests: 100m
      memoryRequests: 128Mi
  
    ## Service Container specific configuration
    ##
    services:
      # cpuLimit: 200m
      # memoryLimit: 256Mi
      cpuRequests: 100m
      memoryRequests: 128Mi
  
    ## Helper Container specific configuration
    ##
    helpers:
      # cpuLimit: 200m
      # memoryLimit: 256Mi
      cpuRequests: 100m
      memoryRequests: 128Mi
      image: gitlab/gitlab-runner-helper:x86_64-latest
  
    ## Service Account to be used for runners
    ##
    # serviceAccountName:
  
    ## If Gitlab is not reachable through $CI_SERVER_URL
    ##
    # cloneUrl:
  
    ## Specify node labels for CI job pods assignment
    ## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
    ##
    nodeSelector: {}
      # gitlab: true
  
  ## Configure resource requests and limits
  ## ref: http://kubernetes.io/docs/user-guide/compute-resources/
  ##
  resources:
    # limits:
    #   memory: 256Mi
    #   cpu: 200m
    requests:
      memory: 128Mi
      cpu: 100m
  
  ## Affinity for pod assignment
  ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
  ##
  affinity: {}
  
  ## Node labels for pod assignment
  ## Ref: https://kubernetes.io/docs/user-guide/node-selection/
  ##
  nodeSelector: {}
    # Example: The gitlab runner manager should not run on spot instances so you can assign
    # them to the regular worker nodes only.
    # node-role.kubernetes.io/worker: "true"
  
  ## List of node taints to tolerate (requires Kubernetes >= 1.6)
  ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
  ##
  tolerations: []
    # Example: Regular worker nodes may have a taint, thus you need to tolerate the taint
    # when you assign the gitlab runner manager with nodeSelector or affinity to the nodes.
    # - key: "node-role.kubernetes.io/worker"
    #   operator: "Exists"
  
  ## Configure environment variables that will be present when the registration command runs
  ## This provides further control over the registration process and the config.toml file
  ## ref: `gitlab-runner register --help`
  ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html
  ##
  envVars:
    - name: RUNNER_EXECUTOR
      value: kubernetes
  
  ```
  
  As you can see, I created a **secret** on my ci job, no error occurred here too. In my chart, I declare this same secret (by his name) in `values.yaml` file, which allow `deployment.yaml` to use it.
  
  Notes:
  
  * If it was the registry, e-g my image repository `registry.gitlab.com/path/to/repo/project/image:TAG_NUMBER` , I will get an error like my image does not exist or something like this. To be more precise, just notice that the var **TAG\_NUMBER** is set in my jobs, and I recover the right value. So I don't think my problem comes from the image repository url.
  * I have tested my secret with a simple pod deployment. All works well with these credentials, the pod is ok (I have use the `kubectl create -f <filename>.yaml` command. I juste read this post about kubernetes and gitlab: <https://docs.gitlab.com/ee/topics/autodevops/#private-project-support>. Maybe it links with my issue.
  
  **Tags:** docker, kubernetes, gitlab, helm, gitlab-ci-runner
  
  > **Comments:**
  > **username_1**: CI credentials for the registry have a lifespan of few minutes usually (5 by default, I don't know for gitlab.com). Feel free to self answer explaining how you solved the problem and accept the answer after :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-07-21. Score: 1
  
  The error you are getting is from your Kubernetes cluster being unable to pull container image from GitLab.
  
  Providing a temporary credential to pull the containers as deploy time is not a great solution. For example, say your Kubernetes cluster needs to scale up by adding another node, the node will come up and try and pull the container, but the secret will be invalid so you won't be able to scale.
  
  I'd create a GitLab static deployment token which has permission to pull images from the GitLab registry: <https://docs.gitlab.com/ee/user/project/deploy_tokens/#read-container-registry-images>
  
  You need to provide this secret to Kubernetes, for that see this document: <https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/>
  
  This should allow you to just do a `helm install` or `helm upgrade` successfully.
  
  
  ---
  
  