Aditi Sharma
Aditi Sharma

Reputation: 503

Kustomize Replacement and prefix Issue: prefix container registry host to Image with missing registry and Registry Replacements for existing images

I'm working on a Kustomize setup where I need to:

Replace the registry for images that already have a registry (e.g., docker.io → 10.20.30.40). Prepend the registry for images without one (e.g., mysql:8.0.29 → 10.20.30.40/mysql:8.0.29).

the original scenario is to bring or download all images from my local registry i.e 10.20.30.40

I tried image prefix as well, thats prefixing to all images and not doing replacement. Not I am trying replacement and its replacing all images first position.

kustomization.yaml

# kustomization.yaml
resources:
- test_two.yaml

replacements:
- source:
    kind: ConfigMap
    name: local-config
    fieldPath: data.registry
  targets:
  - select:
      kind: Deployment
    fieldPaths:
    - spec.template.spec.containers.*.image
    options:
      delimiter: "/"
      index: 0

testing these two images in test_two.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: local-config
  annotations:
    config.kubernetes.io/local-config: "true"
data:
  registry: "10.20.30.40"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    katib.kubeflow.org/component: mysql
  name: katib-mysql
  namespace: kubeflow
spec:
  replicas: 1
  selector:
    matchLabels:
      katib.kubeflow.org/component: mysql
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
      labels:
        katib.kubeflow.org/component: mysql
    spec:
      containers:
      - args:
        - --datadir
        - /var/lib/mysql/datadir
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: katib-mysql-secrets
              key: MYSQL_ROOT_PASSWORD
        - name: MYSQL_ALLOW_EMPTY_PASSWORD
          value: "true"
        - name: MYSQL_DATABASE
          value: "katib"
        image: mysql:8.0.29
        name: katib-mysql
        ports:
        - containerPort: 3306
          name: dbapi
        readinessProbe:
          exec:
            command:
            - /bin/bash
            - -c
            - mysql -D ${MYSQL_DATABASE} -u root -p${MYSQL_ROOT_PASSWORD} -e 'SELECT 1'
          initialDelaySeconds: 10
          periodSeconds: 5
          failureThreshold: 10
        livenessProbe:
          exec:
            command:
            - /bin/bash
            - -c
            - mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}
          initialDelaySeconds: 10
          periodSeconds: 5
          failureThreshold: 10
        startupProbe:
          exec:
            command:
            - /bin/bash
            - -c
            - mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}
          periodSeconds: 15
          failureThreshold: 60
        volumeMounts:
        - name: katib-mysql
          mountPath: /var/lib/mysql
      volumes:
      - name: katib-mysql
        persistentVolumeClaim:
          claimName: katib-mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    katib.kubeflow.org/component: ui
  name: katib-ui
  namespace: kubeflow
spec:
  replicas: 1
  selector:
    matchLabels:
      katib.kubeflow.org/component: ui
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
      labels:
        katib.kubeflow.org/component: ui
    spec:
      containers:
      - args:
        - --port=8080
        command:
        - ./katib-ui
        env:
        - name: KATIB_CORE_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: APP_DISABLE_AUTH
          value: "false"
        image: docker.io/kubeflowkatib/katib-ui:v0.17.0
        name: katib-ui
        ports:
        - containerPort: 8080
          name: ui
      serviceAccountName: katib-ui

output :

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    katib.kubeflow.org/component: mysql
  name: katib-mysql
  namespace: kubeflow
spec:
  replicas: 1
  selector:
    matchLabels:
      katib.kubeflow.org/component: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
      labels:
        katib.kubeflow.org/component: mysql
    spec:
      containers:
      - args:
        - --datadir
        - /var/lib/mysql/datadir
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              key: MYSQL_ROOT_PASSWORD
              name: katib-mysql-secrets
        - name: MYSQL_ALLOW_EMPTY_PASSWORD
          value: "true"
        - name: MYSQL_DATABASE
          value: katib
        image: 10.20.30.40 ----here i want ip followed by original image mysql:8.0.29 and expected is 10.20.30.40/mysql:8.0.29
        livenessProbe:
          exec:
            command:
            - /bin/bash
            - -c
            - mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}
          failureThreshold: 10
          initialDelaySeconds: 10
          periodSeconds: 5
        name: katib-mysql
        ports:
        - containerPort: 3306
          name: dbapi
        readinessProbe:
          exec:
            command:
            - /bin/bash
            - -c
            - mysql -D ${MYSQL_DATABASE} -u root -p${MYSQL_ROOT_PASSWORD} -e 'SELECT
              1'
          failureThreshold: 10
          initialDelaySeconds: 10
          periodSeconds: 5
        startupProbe:
          exec:
            command:
            - /bin/bash
            - -c
            - mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}
          failureThreshold: 60
          periodSeconds: 15
        volumeMounts:
        - mountPath: /var/lib/mysql
          name: katib-mysql
      volumes:
      - name: katib-mysql
        persistentVolumeClaim:
          claimName: katib-mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    katib.kubeflow.org/component: ui
  name: katib-ui
  namespace: kubeflow
spec:
  replicas: 1
  selector:
    matchLabels:
      katib.kubeflow.org/component: ui
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
      labels:
        katib.kubeflow.org/component: ui
    spec:
      containers:
      - args:
        - --port=8080
        command:
        - ./katib-ui
        env:
        - name: KATIB_CORE_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: APP_DISABLE_AUTH
          value: "false"
        image: 10.20.30.40/kubeflowkatib/katib-ui:v0.17.0  ----- this is correct as expected
        name: katib-ui
        ports:
        - containerPort: 8080
          name: ui
      serviceAccountName: katib-ui

Note: don't want with container runtime

Upvotes: 0

Views: 29

Answers (0)

Related Questions