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

Deploy a Docker image to Kubernetes

If you store Docker images in Container Registry, you can deploy under to a Managed Kubernetes cluster or to 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.

1. Load the image into the 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>

2. 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 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 Access the Registry.
  5. Select Integrate 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 labeled as INACTIVE.
  8. If you are setting up an 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 the registry name.

3. Deploy the application from the 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 pods — they should be in running status:

    kubectl get pods