Deploy a Docker image to Kubernetes
If you store Docker images in Container Registry, you can deploy a pod in a Managed Kubernetes cluster or in a Kubernetes cluster that you manage yourself.
- Upload the image to the Container Registry registry.
- Configure Container Registry integration with the cluster.
- Deploy the application from the image.
1. Upload the image to Container Registry
-
Enter your username and password.
-
Assign a tag to the image:
docker tag <image> cr.selcloud.ru/<registry>/<image>:<tag>Specify:
<image>— image name, can be viewed usingdocker image list;<registry>— name of the registry to upload the image to;<tag>— tag.
-
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 the Kubernetes cluster, you create a Secret object — a secret with Container Registry token data yourself.
Managed Kubernetes
Kubernetes
You can configure integration from Container Registry with one or more Managed Kubernetes clusters.
- In the Control panel, in the top menu, click Products and select Container Registry.
- Open the Registries tab.
- Open the registry page.
- Click Registry access.
- Select Integration with Kubernetes.
- Click Continue.
- 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 asINACTIVE. - If you are configuring the integration for the first time, click Integrate.
- 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
Managed Kubernetes
Kubernetes
-
Create a deployment.yaml file:
nano deployment.yaml -
Copy the content into the file:
apiVersion: apps/v1kind: Deploymentmetadata:name: example-deploymentlabels:app: example-deploymentspec:replicas: 2selector:matchLabels:app: example-deploymenttemplate:metadata:labels:app: example-deploymentspec:containers:- name: <image_name>image: cr.selcloud.ru/<registry>/<image>:latestimagePullSecrets:- name: craas-authSpecify:
<registry>— registry name;<image_name>— image name.
-
Deploy the application:
kubectl apply -f deployment.yaml -
Check the pod status — they should be in the
runningstatus:kubectl get pods