Deploy a Docker image to Kubernetes
If you store Docker images in the Container Registry, you can deploy under to a [Managed Kubernetes] cluster(/cloud/managed-kubernetes/about/about-managed-kubernetes.mdx) or to a Kubernetes cluster that you administer yourself.
- Upload image to Container Registry.
- Configure Container Registry integration with cluster.
- Deploy application from image.
Upload the image to Container Registry
-
Enter 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 withdocker image list
;<registry>
is the name of the registry where you want to load the image;<tag>
— Tag.
-
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 the object Secret — secret with Container Registry token data by yourself.
- Managed Kubernetes
- Kubernetes
You can configure integration from Container Registry with one or more Managed Kubernetes clusters.
- In Control Panel, go to Cloud Platform → Container Registry.
- Open the registry page.
- Click Registry Access.
- Select Integration with Kubernetes.
- Press Continue.
- Select the Managed Kubernetes clusters that will be granted access to the selected registry. You can only select clusters with status
ACTIVE
. Clusters with other statuses are labeled as `INACTIVE'. - If you are setting up 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 the registry name.
-
Create a secret:
kubectl create secret docker-registry <secret_name> {
--docker-server=cr.selcloud.ru {
--docker-username=<username> {
--docker-password=<password> {
--namespace=<namespace>Specify:
<secret_name>
is the name of the secret;<username>
is the username created when the token was received;<password>
— the password created when the token was received;<namespace>
— optional: if you are creating the container in a namespace other than default, specify the name of your namespace.
-
Check that the secret has been created:
kubectl get secret <secret_name> --output=yaml
Deploy the application from the image
- Managed Kubernetes
- Kubernetes
-
Create a deployment.yaml file:
nano deployment.yaml
-
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>:latestSpecify:
<registry>
is the name of the registry;<image_name>
is the name of the image.
-
Deploy the application:
kubectl apply -f deployment.yaml
-
Check the status of the pods — they should be in
running
status:kubectl get pods
-
Create a deployment.yaml file:
nano deployment.yaml
-
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
imagePullSecrets:
- name: <secret_name>Specify:
<registry>
is the name of the registry;<image_name>
is the name of the image;<secret_name>
is the name of the secret.
-
Deploy the application:
kubectl apply -f deployment.yaml
-
Check the status of the pods — they should be in
running
status:kubectl get pods