Continental Innovates with Rancher and Kubernetes
This article is a continuation of Deploying JFrog Artifactory with Rancher. In this chapter we’ll demonstrate how to use JFrog Artifactory as a private repository for your own Docker images.
NOTE: This feature of JFrog Artifactory requires a license, but you can get a 30-day trial and use it to follow along.
If you plan to use Artifactory as a repository for Docker outside of your local network, you’ll need a public IP address. In the first part of this article we deployed our cluster into Google Cloud, and we’ll continue to use GCP resources now.
You can reserve a public IP by running the following command in the Google Cloud Shell or in your local environment via the gcloud command:
gcloud compute addresses create artifactory-demo --global
Use the name you chose (artifactory-demo in our case) to retrieve the address:
gcloud compute addresses describe artifactory-demo --global
Look for the address label in the output:
We’ll use the magical xip.io service from Basecamp to assign a fully-qualifed domain name to our service, which in our case will be 188.8.131.52.xip.io.
You can follow the steps in the previous chapter to deploy Rancher and Artifactory, but when you reach the part about configuring the variables in the app deployment page, add or change the following variables:
(You can copy/paste that block of text into a field, and Rancher will convert it for you.)
When all is done, it should look like the image below:
Click Launch to begin deploying the resources.
While your new Artifactory instance spins up, let’s look at what we just configured.
This enables the creation of an ingress resource, which will serve as a proxy for Artifactory. In our case the Ingress will be a load balancer within GCP.
This sets the hostname for Artifactory. Part of the magic of xip.io is that we can create any subdomain and have it resolve back to the IP, so when we use docker-demo.184.108.40.206.xip.io later in this walkthrough, it will resolve to 220.127.116.11.
This exposes Artifactory’s service via a random port on the Kubernetes node. The Ingress resource will send traffic to this port.
Because we’re using the Ingress resource to talk to Artifactory via the Service resource, we want to disable the nginx proxy that Artifactory would otherwise start.
This is the glue that ties Kubernetes to the static public IP address. We set this to the name of the address that you reserved so that the Ingress finds and uses the correct IP. We had to escape a large part of it because that’s the name of the annotation. Without escaping the elements, Kubernetes would misunderstand what we were asking it to do.
Once the deployment completes, look at the Workloads tab. There you will see two workloads. One is the application (artifactory-artifactory), and the other is the PostgreSQL database that artifactory uses (artifactory-postgresql).
Look at the Load Balancing tab next. There you will see the Ingress object with the hostname that we provided.
If you select View/Edit YAML and scroll to the bottom, you will see the annotation that points to the address name in GCP (line 10 in the image):
At the bottom of the Ingress definition you will also see that the hostname in spec.rules.host matches the IP address from status.loadBalancer.ingress.ip at the bottom.
When you close the View/Edit YAML window, you’ll return to the Load Balancing tab. There you’ll find a link with the xip.io address. Click it to open Artifactory, or just enter the hostname into your browser.
Click through the wizard, first adding your license key and then setting an admin password. Click through the rest until the wizard completes.
In the menu on the left side, select Admin, and then under Repositories select Local.
There you will see the default repository created by the setup wizard. Select + New from the upper right corner to create a new repository. Choose Docker as the package type and enter a name for the repository. In our case we chose docker-demo. Leave everything else at the defaults and select Save & Finish to create the new repository.
The name that you chose (docker-demo for us) becomes the subdomain for your xip.io domain. For our installation, we’ll be using docker-demo.18.104.22.168.xip.io. Yours will of course be different, but it will follow the same format.
What fun is it to have a private Docker repository if you don’t use it?
For a production deployment you would secure the registry with an SSL certificate, and that would require a real hostname on a real domain. For this walkthrough, though, you can use the newly-created registry by telling Docker that it’s an insecure registry.
Create or edit daemon.json according to the documentation, adding your host like we do in the following example:
If you use Docker for Mac or Docker for Windows, set this in the preferences for the application:
Restart Docker for it to pick up the changes, and after it restarts, you can use the registry:
docker login docker-demo.22.214.171.124.xip.io
To continue with the test, we’ll pull a public container image, re-tag it, and then push it to the new private registry.
$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
f17d81b4b692: Pull complete
d5c237920c39: Pull complete
a381f92f36de: Pull complete
Status: Downloaded newer image for nginx:latest
You can see the current image id and information on your system:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest dbfc48660aeb 2 days ago 109MB
Re-tag it so that Docker knows to push it to your new private registry:
$ docker tag nginx docker-demo.126.96.36.199.xip.io:80/nginx:latest
With the image re-tagged, use docker push to send it to your private registry:
$ docker push docker-demo.188.8.131.52.xip.io:80/nginx:latest
The push refers to repository [docker-demo.184.108.40.206.xip.io:80/nginx]
latest: digest: sha256:d98b66402922eccdbee49ef093edb2d2c5001637bd291ae0a8cd21bb4c36bebe size: 948
Back in the Artifactory UI, select Artifacts from the menu.
There you’ll see your nginx image and information about it.
If you have an Artifactory License and want to run a private registry, repeat this walkthrough using your own domain and an SSL certificate on the ingress. With those additional items complete, you’ll be able to use the private registry with any Docker or Kubernetes installation without having to tell the host that it has permission to talk to an insecure registry.
To clean up the resources that we used in this article, delete the Kubernetes cluster from Rancher and then delete the Rancher server from GCP:
gcloud compute --project=rancher-20 instances delete \
You’ll also need to delete the public IP address reservation:
gcloud compute addresses delete artifactory-demo --global
JFrog Artifactory provides services that are at the core of a development lifecycle. You can store and retrieve almost any type of artifact that your development teams produce, and having these artifacts stored in a central, managed location makes Artifactory an important part of any IT infrastructure.
Rancher makes it easy to deploy Artifactory into a Kubernetes installation. In only a few minutes we had Artifactory up and running, and it actually took longer to configure Artifactory itself than it did to install it!
Rancher makes Kubernetes easy. Artifactory makes managing binary resources easy. Together they free you to focus on the things that matter for your business, and that freedom is what matters most.