W
W
web_dev2018-06-25 14:03:10
Devops
web_dev, 2018-06-25 14:03:10

Automatically ip(service name) in deployment?

Hello,
I started getting acquainted with Kubernetes a little. I want to run a small DockerRegistry. At the same time, I want everything that needs to be started with one config.
When starting registry-frontend, you need to specify the address to the service / pod where DockerRegistry is running.
How can I specify in the configuration that the registry is available at the address of the registry service?
To run the config in one fell swoop.
Could not reach the service via dns. Although I try the same way as I write in the documentation.

[[email protected] tmp]# curl http://registry.tools.svc.cluster.local:5000
curl: (6) Could not resolve host: registry.tools.svc.cluster.local; Unknown error

Thanks for the hints. Here is the config, I want to automatically fill in the variable ENV_DOCKER_REGISTRY_HOST.
apiVersion: v1
kind: Service
metadata:
  name: registry
  labels:
    app: tools
spec:
  type: NodePort
  ports:
  - port: 5000 
    name: registry
    targetPort: 5000
    nodePort: 31111
  selector:
    app: tools
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: registry
spec:
  selector:
    matchLabels:
      app: tools
  replicas: 1
  template:
    metadata:
      labels:
        app: tools
    spec:
      containers:
      - name: registry
        image: registry:2
        ports:
        - containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
  name: registry-frontend
  labels:
    app: tools
spec:
  type: NodePort
  ports:
  - port: 80 
    name: nginx
    targetPort: 80 
    nodePort: 31222 
  selector:
    app: tools
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: registry-frontend
spec:
  selector:
    matchLabels:
      app: tools
  replicas: 1
  template:
    metadata:
      labels:
        app: tools
    spec:
      containers:
      - name: registry-frontend
        image: konradkleine/docker-registry-frontend:v2
        ports:
        - containerPort: 80
        env:
        - name: ENV_DOCKER_REGISTRY_HOST
          value: "10.233.75.18"
        - name: ENV_DOCKER_REGISTRY_PORT
          value: "5000"

Thanks for the tips!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question