Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve images from a private Nexus repository using a K8s cluster, you can follow the below steps:

  1. Create a Kubernetes Secret which will store your Nexus repository credentials:
apiVersion: v1
kind: Secret
metadata:
  name: nexus-repo-cred
type: Opaque
data:
  username: <base64 encoded username>
  password: <base64 encoded password>
  1. Create a Kubernetes Pod with the necessary environment variables and volume mounts to mount the credentials to retrieve images from Nexus:
apiVersion: v1
kind: Pod
metadata:
  name: nexus-pod
spec:
  containers:
    - name: test
      image: <your-image>
      env:
        - name: NEXUS_USERNAME
          valueFrom:
            secretKeyRef:
              name: nexus-repo-cred
              key: username
        - name: NEXUS_PASSWORD
          valueFrom:
            secretKeyRef:
              name: nexus-repo-cred
              key: password
      volumeMounts:
        - name: nexus-creds
          mountPath: /etc/nexus-creds
  volumes:
    - name: nexus-creds
      secret:
        secretName: nexus-repo-cred
  1. Specify the image pull secret in your Kubernetes Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: <your-deployment>
  labels:
    app: <your-app>
spec:
  replicas: 1
  selector:
    matchLabels:
      app: <your-app>
  template:
    metadata:
      labels:
        app: <your-app>
    spec:
      containers:
        - name: <your-container>
          image: <your-image>
      imagePullSecrets:
        - name: nexus-repo-cred

After following these steps, your Kubernetes cluster should be able to retrieve images from your private Nexus repository.