N
N
noute2019-09-30 15:24:24
linux
noute, 2019-09-30 15:24:24

How to run a Docker registry image in Kubernetes?

Hello, I recently started learning kubernetes 2 questions.
1. How to run an image from the Docker registry in Kubernetes?
2. I do this but it doesn't work.
docker run -it httpd /bin/sh
docker commit -m "test" httpd name-image
and then try to run
kubectl create deployment nginx --image=httpd
Am I doing it right?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
OxCom, 2019-10-05
@noute

Good afternoon. From the description it is not clear where, what and how you are doing. Let's play a guessing game:
1) minikube:
Go to the minikube shell and do something with the built-in docker and work with images there. Something like this:

host$ docker run -d nginx:latest
host$ docker exec -it <container> /bin/sh
container$ # hack, hack, hack...
container$ exit
host$ docker commit <container> <yuour-image-name:and-tag-here>

After that, you can use the new image in minikube, where you made changes. Remember that minikube is different from a real k8s cluster.
2) k8s cloud or baremetal
Here you need to create your own registry for your images. It is best to raise it separately so that when you create a new cluster, you do not need to collect all versions of your docker images (otherwise where will he get these images?).
Let's say there is some kind of private registry with login and password access. To use it, you need to create a secret in k8s with a configuration that stores the desired pair of login and password.
apiVersion: v1
kind: Secret
type: kubernetes.io/dockerconfigjson
data:
    .dockerconfigjson: <configuration>
metadata:
    name: registry-secret

How to do it, read here
Next, we can use a private registry like this:
# ...
spec:
  imagePullSecrets:
    -   name: registry-secret
  # ...
  containers:		
    -   name: php
      image: <private-registry-domain>/<image-name:tag-here>

You can also do authorization by keys, but that's another story, which will pull on an article on Habré.

D
Dmitry, 2019-09-30
@q2digger

Here is an article that immediately answers all questions. official guide on the official website.
https://kubernetes.io/docs/concepts/workloads/cont...
in the deployment, the containers section is your docker container.

spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

N
noute, 2019-09-30
@noute

Maybe there is some kind of article or something with sensible examples?
I will be grateful

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question