Skip to content

Instantly share code, notes, and snippets.

@matiasah
Last active June 6, 2023 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matiasah/8b6a2a4f79a48c41713822bda7d708e2 to your computer and use it in GitHub Desktop.
Save matiasah/8b6a2a4f79a48c41713822bda7d708e2 to your computer and use it in GitHub Desktop.
Configure a Container Image Registry with Kubernetes
  1. To authenticate to the private registry
docker login registry.gitlab.com
  1. Create the docker authentication credential as a Kubernetes secret (regcred)
kubectl create secret generic regcred \
    --from-file=.dockerconfigjson=$HOME/.docker/config.json \
    --type=kubernetes.io/dockerconfigjson \
    --namespace=your-kubernetes-namespace-here
  1. To configure the credential on a docker-compose yaml (for Kompose).
version: "3.7"

services:
  
  st-gateway-service:
    image: registry.gitlab.com/your-container-image-here:latest
    container_name: your-container-name-here
    restart: always
    ports:
      - "8080:8080"
    env_file:
      - .env
    environment:
      - TZ=America/Santiago
    labels:
      #kompose.service.expose: PUBLIC-IP-ADDRESS (OPTIONAL)
      kompose.controller.type: deployment
      kompose.image-pull-secret: regcred
  1. Transform docker-compose to Kubernetes manifest using "kompose"
kompose convert -f docker-compose.yml -o kubectl/prod/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment