Jump toUpdate content
How to deploy an image from Scaleway Elements Container Registry to Kubernetes Kapsule
A container image consists of several bundled files, which encapsulate an application. This image can be built on a local machine, uploaded to the image registry, and then deployed on several Kubernetes pods with Kapsule. Kapsule is the managed Kubernetes service provided by Scaleway Elements. In this tutorial we use Docker to build the containers.
- You have an account and are logged into the Scaleway Console
- You have created a Kubernetes Kapsule cluster and downloaded and configured the corresponding
- You have installed Docker and kubectl on your local computer.
- You have created an API key
To complete the following steps, it is required that you have a local project with a
Dockerfile to build a container image from it. If you do not have a Docker project yet, you may follow our tutorial to create the required files.
Open a terminal window on your local computer.
Check that all required files are available to build the container image by running the
ls -lcommand in the directory of your project:
$ ls -l
-rw-r--r-- 1 myuser staff 903 Oct 14 12:19 Dockerfile
-rw-r--r-- 1 myuser staff 1080 Oct 14 12:19 LICENSE
-rw-r--r-- 1 myuser staff 476 Oct 14 12:19 Makefile
-rw-r--r-- 1 myuser staff 1721 Oct 14 12:19 README.md
drwxr-xr-x 3 myuser staff 96 Oct 14 12:19 patches
Use the following commands to build the Docker container image locally before pushing it to your private Container Registry. The parameter
-tconfigures the tags of the container:
$ docker build -t mycontainer:latest .
Sending build context to Docker daemon 197.6kB
Successfully built c427b132b5fc
Successfully tagged mycontainer:latest
Check that the image has been added to the local Docker installation by running the
docker imagescommand. Your newly created container image will be displayed in the list of available images:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycontainer latest c427b132b5fc 22 minutes ago 1.24GB
Log into your Container Registry. The endpoint (for example:
rg.fr-par.scw.cloud/myregistry) of your Container Registry is available from the Scaleway Elements Console and depends on your configuration:
$ docker login rg.fr-par.scw.cloud/myregistry -u nologin -p $SCW_SECRET_KEY
Login Succeededmessage displays once logged in.
Tag the image using the
docker tagcommand. Make sure to replace the URL of the registry with your personal endpoint:
$ docker tag mycontainer:latest rg.fr-par.scw.cloud/myregistry/mycontainer:latest
Push the image to the registry using the
$ docker push rg.fr-par.scw.cloud/myregistry/mycontainer:latest
latest: digest: sha256:690d70e8f26cb772916c64244c86701c50f2764e42c668d4d0aaf039a9d62b47 size: 4067
To deploy the previously created container image in a Kapsule cluster, you need to create an Image Pull Secret. For this, your API Secret Key is required.
kubectlto define a secret called
$SCW_SECRET_KEYvariable as follows:
$ kubectl create secret docker-registry registry-secret --docker-server=rg.fr-par.scw.cloud --docker-username=myuser --docker-password=$SCW_SECRET_KEY --firstname.lastname@example.orgImportant: Only docker-server and docker-password in the command above concern the image registry.
Display the generated secret with the
kubectl get secretcommand. The flag
--output=yamlwill return the output formatted in YAML:
$ kubectl get secret registry-secret --output=yaml
Create a file
deployment.yamland open it in a text editor, e.g.
$ nano deployment.yaml
Copy the following content into it, save the file and quit the text editor.
Remember to replace the image name
rg.fr-par.scw.cloud/myregistry/mycontainer:latestand registry secret
registry-secretwith the values you previously defined.
- name: mycontainer
- name: registry-secretNote:
In the configuration above, the secret and deployments are in the same namespace.
kubectl applyto apply the deployment to the cluster:
$ kubectl apply -f deployment.yaml
kubectl get podscommand to check the status of the deployment:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
mydeployment-64c9fdd66c-66mrq 1/1 Running 0 2m
mydeployment-64c9fdd66c-pwhl9 1/1 running 0 2m
As you can see in the output above, the image has been pulled successfully from the registry and two replicas of it are running on the Kapsule cluster.
For more information how to use your Container Registry with Kubernetes, refer to the official documentation.