st-tech / gatling-operator

Automating distributed Gatling load testing using Kubernetes operator
MIT License
68 stars 21 forks source link

Pull container image from private registry? #47

Closed Rindrics closed 2 years ago

Rindrics commented 2 years ago

Thank you for developing useful tool!

Is there any way to use container images placed in a private registry?

Context

I specified my container image in gatling-operator_v1alpha1_gatling01.yaml as follows:

apiVersion: gatling-operator.tech.zozo.com/v1alpha1
kind: Gatling
metadata:
  name: gatling-sample01
spec:
  generateReport: false
  generateLocalReport: false
  notifyReport: false
  cleanupAfterJobDone: true
  podSpec:
    serviceAccountName: "gatling-operator-worker"
    gatlingImage: myPriveteRepo.io/foo:latest

Applying the yaml above of course cause ImagePullBackOff error.

What I tried

I tried adding imagePullSecret: mysecret to the yaml, but found the current API does not support it.

Thanks,

yokawasa commented 2 years ago

@Rindrics thanks you for the question!

Actually Gatling CR does NOT support to add imagePullSecret definition to Gatling CR at this point. We'll consider to add the feature.

But there is a workaround to pull the image from private registry. Here is a procedure

1. create an "image pull secret" in the namespace to which you deploy your Gatling CR

Suppose you want to deploy your gatling CR (ie, 'gatling-sample01') to default namespace, create an "image pull secret" like this

PASS=xxxxxx
NAMESPACE=default
kubectl create secret docker-registry mysecret --docker-server=<registry server name> --docker-username=<registry-accout-name> --docker-password=$PASS --docker-email=your@mail.com -n $NAMESPACE

So your image pull secret named mysecret was created under default namespace

2. Add ImagePullSecrets to a service account

Suppose you define service account named gatling-operator-worker in your Gatling CR, modify the gatling-operator-worker service account for the namespace to use this secret as an imagePullSecret like this:

NAMESPACE=default
kubectl patch serviceaccount gatling-operator-worker -p "{\"imagePullSecrets\": [{\"name\": \"mysecret\"}]}" -n $NAMESPACE

Now you're ready to deploy your galting CR where private image is defined.

apiVersion: gatling-operator.tech.zozo.com/v1alpha1
kind: Gatling
metadata:
  name: gatling-sample01
spec:
  generateReport: false
  generateLocalReport: false
  notifyReport: false
  cleanupAfterJobDone: true
  podSpec:
    serviceAccountName: "gatling-operator-worker"
    gatlingImage: myPriveteRepo.io/foo:latest

Hope this would help

useful links

Rindrics commented 2 years ago

Thanks to your instruction, I managed to pull the image and let Gatling containers run!

Thank you so much for your detailed instruction.

yokawasa commented 2 years ago

@Rindrics thank you for the confirmation!!