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.
- Load the image into the Container Registry.
- Configure Container Registry integration with the cluster.
- Deploy the application from the image.
Upload 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>
— 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 an object Secret — secret with Container Registry token data on its own.
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.
- Click Continue.
- 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 asINACTIVE
. - 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>
— the name of the secret;<username>
— 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 an application from an 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>
— registry name;<image_name>
— image name.
-
Deploy the application:
kubectl apply -f deployment.yaml
-
Check the status of the pods — they should be in status
running
: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>
— registry name;<image_name>
— image name;<secret_name>
— the name of the secret.
-
Deploy the application:
kubectl apply -f deployment.yaml
-
Check the status of the pods — they should be in status
running
:kubectl get pods