Skip to main content
Deploy a Docker image to Kubernetes
Last update:

Deploy a Docker image to Kubernetes

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

  1. Load the image into the Container Registry.
  2. Configure Container Registry integration with the cluster.
  3. Deploy the application from the image.

Upload image to Container Registry

  1. Authorize the registry.

  2. Enter 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 with docker image list;
    • <registry> — name of the registry where you want to load the image;
    • <tag> — Tag.
  4. Load the image into the registry:

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

Configure Container Registry integration with the cluster

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

In a Kubernetes cluster, you create an object Secret — secret with Container Registry token data on its own.

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

  1. В control panels go to Cloud platformContainer Registry.
  2. Open the registry page.
  3. Click Registry access.
  4. Select Integration with Kubernetes.
  5. Click Continue.
  6. Select the Managed Kubernetes clusters that will be granted access to the selected registry. You can select only clusters with status ACTIVE. Clusters with other statuses are designated as INACTIVE.
  7. If you are setting up the integration for the first time, click Integrate.
  8. 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 the registry name.

Deploy an application from an image

  1. Create a deployment.yaml file:

    nano deployment.yaml
  2. Copy the contents 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 status of the pods — they should be in status running:

    kubectl get pods