Skip to main content

Deploy a Docker image to Kubernetes

Last update:

If you store Docker images in the Container Registry, you can deploy a pod in a Managed Kubernetes cluster or in a Kubernetes cluster that you administer yourself.

  1. Upload the image to Container Registry.
  2. Configure Container Registry integration with the cluster.
  3. Deploy the application from the image.

1. Upload the image to Container Registry

  1. Log in to the registry.

  2. Enter your username and password.

  3. Assign a tag to the image:

    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:

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

2. Configure Container Registry integration with the 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 object — a secret with Container Registry token data — yourself.

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

  1. In the control panel 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 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.

3. Deploy the application from the image

  1. Create a deployment.yaml file:

    nano deployment.yaml
  2. Copy the content into the file:

    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:

    kubectl apply -f deployment.yaml
  4. Check the pod status — they should have a status of running:

    kubectl get pods