---
title: "Deploy a Docker image to Kubernetes"
sidebar_label: "Deploy a Docker image to Kubernetes"
description: "How to upload a Docker image, configure integration with a cluster, and deploy an application from the image"
sidebar_position: 4
---

import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'
import Formbricks from '@theme/MDXComponents/Formbricks'

# Deploy a Docker image to Kubernetes

If you store Docker images in the Container Registry, you can deploy a pod in a [Managed Kubernetes](/managed-kubernetes/about/about-managed-kubernetes.mdx) cluster or in a Kubernetes cluster that you administer yourself.

1. [Upload the image to Container Registry](#upload-image).
2. [Configure Container Registry integration with the cluster](#configure-registry-integration-with-cluster).
3. [Deploy the application from the image](#deploy-application-from-image).

## 1. Upload the image to Container Registry \{#upload-image}

1. [Log in to the registry](/craas/images/use-docker.mdx).

2. Enter your username and password.

3. Assign a tag to the image:

   ```bash
   docker tag <image> cr.selcloud.ru/<registry>/<image>:<tag>
   ```

   Specify:

   * `<image>` — image name, can be viewed using `docker image list`;
   * `<registry>` — name of the registry to which you want to upload the image;
   * `<tag>` — tag.

4. Upload the image to the registry:

   ```bash
   docker push cr.selcloud.ru/<registry>/<image>:<tag>
   ```

## 2. Configure Container Registry integration with the cluster \{#configure-registry-integration-with-cluster}

For a Managed Kubernetes cluster, after integration, authentication data is automatically added to the default service account and to a secret for all cluster namespaces.

In a Kubernetes cluster, you create a [Secret](https://kubernetes.io/docs/concepts/configuration/secret/) object — a secret with Container Registry token data — yourself.

<Tabs queryString="configure-registry-integration-with-cluster">
  <TabItem value="managed-kubernetes" default>
    <TabItemLabel>
      Managed Kubernetes
    </TabItemLabel>

    You can configure integration from Container Registry with one or more Managed Kubernetes clusters.

    1. In the [control panel](https://my.selectel.ru/vpc/default/craas/) on the top menu, click **Products** and select **Container Registry**.
    2. Open the **Registries** tab.
    3. Open the registry page.
    4. Click **Registry access**.
    5. Select **Integration with Kubernetes**.
    6. Click **Continue**.
    7. Select the Managed Kubernetes clusters that will be granted access to the selected registry. You can only select clusters with the [status](/managed-kubernetes/clusters/cluster-statuses.mdx) `ACTIVE`. Clusters with other statuses are marked as `INACTIVE`.
    8. If you are setting up the integration for the first time, click **Integrate**.
    9. If you are changing the integration settings, click **Save**.

    Information about the Managed Kubernetes clusters that have been granted access to the selected registry is displayed on the registry page, under its name.
  </TabItem>

  <TabItem value="kubernetes">
    <TabItemLabel>
      Kubernetes
    </TabItemLabel>

    1. Create a secret:

       ```shell
       kubectl create secret docker-registry <secret_name> \
         --docker-server=cr.selcloud.ru \
         --docker-username=<username> \
         --docker-password=<password> \
         --namespace=<namespace>
       ```

       Specify:

       * `<secret_name>` — secret name;
       * `<username>` — username created when the token was received;
       * `<password>` — password created when the token was received;
       * `<namespace>` — optional: if you are creating a container in a namespace other than default, specify the name of your namespace.

    2. Check that the secret has been created:

       ```bash
       kubectl get secret <secret_name> --output=yaml
       ```
  </TabItem>
</Tabs>

## 3. Deploy the application from the image \{#deploy-application-from-image}

<Tabs queryString="deploy-application-from-image">
  <TabItem value="managed-kubernetes" default>
    <TabItemLabel>
      Managed Kubernetes
    </TabItemLabel>

    1. Create a deployment.yaml file:

       ```bash
       nano deployment.yaml
       ```

    2. Copy the content into the file:

       ```yaml
       apiVersion: apps/v1
       kind: Deployment
       metadata:
         name: example-deployment
         labels:
           app: example-deployment
       spec:
         replicas: 2
         selector:
           matchLabels:
             app: example-deployment
         template:
           metadata:
             labels:
               app: example-deployment
           spec:
             containers:
             - name: <image_name>
               image: cr.selcloud.ru/<registry>/<image>:latest
       ```

       Specify:

       * `<registry>` — registry name;
       * `<image_name>` — image name.

    3. Deploy the application:

       ```bash
       kubectl apply -f deployment.yaml
       ```

    4. Check the pod status — they should have a status of `running`:

       ```bash
       kubectl get pods
       ```
  </TabItem>

  <TabItem value="kubernetes">
    <TabItemLabel>
      Kubernetes
    </TabItemLabel>

    1. Create a deployment.yaml file:

       ```bash
       nano deployment.yaml
       ```

    2. Copy the content into the file:

       ```yaml
       apiVersion: apps/v1
       kind: Deployment
       metadata:
         name: example-deployment
         labels:
           app: example-deployment
       spec:
         replicas: 2
         selector:
           matchLabels:
             app: example-deployment
         template:
           metadata:
             labels:
               app: example-deployment
           spec:
             containers:
             - name: <image_name>
               image: cr.selcloud.ru/<registry>/<image>:latest
             imagePullSecrets:
             - name: <secret_name>
       ```

       Specify:

       * `<registry>` — registry name;
       * `<image_name>` — image name;
       * `<secret_name>` — secret name.

    3. Deploy the application:

       ```bash
       kubectl apply -f deployment.yaml
       ```

    4. Check the pod status — they should have a status of `running`:

       ```bash
       kubectl get pods
       ```
  </TabItem>
</Tabs>

<Formbricks />
