Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: registry addon #170

Merged
merged 8 commits into from
Dec 8, 2021
Merged

feat: registry addon #170

merged 8 commits into from
Dec 8, 2021

Conversation

shaneutt
Copy link
Contributor

@shaneutt shaneutt commented Dec 1, 2021

This PR adds a registry addon so that a container image registry can be loaded into the cluster and be made available for pods.

In order to accomplish this several new utilities were added, highlights include:

  • utilities for running commands and reading/writing files in docker containers
  • certificate management utilities to simplify creating cert-manager certificates
  • networking utilities for kubernetes

This new addon brings several benefits including:

  • resolves A registry addon #147
  • helps support testing workflows where images need to be rapidly built and deployed into the test cluster
  • easily seed images from cache in CI

This is the first iteration of this addon but is incomplete: this works using a self-signed certificate and only on kind clusters. The current certificate management landscape in a KTF cluster is limited and the default cluster CA feature is desired prior to adding support for GKE so that certificate trust configuration no longer needs to be a part of the addon deployment as was done here, but instead cluster setup.

@shaneutt shaneutt added area/feature New feature or request priority/medium labels Dec 1, 2021
@shaneutt shaneutt self-assigned this Dec 1, 2021
@shaneutt shaneutt temporarily deployed to integration-tests December 1, 2021 22:04 Inactive
@shaneutt shaneutt force-pushed the shaneutt/registry-addon branch from 70dfc9f to f10457e Compare December 1, 2021 22:12
@shaneutt shaneutt temporarily deployed to integration-tests December 1, 2021 22:12 Inactive
@shaneutt shaneutt force-pushed the shaneutt/registry-addon branch from f10457e to e8394f6 Compare December 2, 2021 20:13
@shaneutt shaneutt temporarily deployed to integration-tests December 2, 2021 20:13 Inactive
@shaneutt shaneutt force-pushed the shaneutt/registry-addon branch from e8394f6 to 45e7276 Compare December 2, 2021 20:14
@shaneutt shaneutt temporarily deployed to integration-tests December 2, 2021 20:14 Inactive
@shaneutt shaneutt force-pushed the shaneutt/registry-addon branch from 45e7276 to b2fe42c Compare December 2, 2021 20:29
@shaneutt shaneutt temporarily deployed to integration-tests December 2, 2021 20:29 Inactive
@shaneutt shaneutt marked this pull request as ready for review December 2, 2021 20:30
@shaneutt shaneutt requested a review from a team as a code owner December 2, 2021 20:30
@shaneutt shaneutt enabled auto-merge (rebase) December 2, 2021 21:56
Copy link
Contributor

@rainest rainest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor doc grammar stuff in suggestions. I think we should also mention the --tlsverify=false option as an alternative to loading certificates--I expect most users will be okay with that for tests.

internal/cmd/ktf/environments.go Outdated Show resolved Hide resolved
internal/cmd/ktf/environments.go Outdated Show resolved Hide resolved
@shaneutt shaneutt force-pushed the shaneutt/registry-addon branch from 6027a61 to 5350173 Compare December 8, 2021 15:06
@shaneutt shaneutt requested a review from rainest December 8, 2021 15:06
@shaneutt shaneutt temporarily deployed to integration-tests December 8, 2021 15:06 Inactive
@rainest rainest temporarily deployed to integration-tests December 8, 2021 18:37 Inactive
@shaneutt shaneutt merged commit e333a54 into main Dec 8, 2021
@shaneutt shaneutt deleted the shaneutt/registry-addon branch December 8, 2021 18:56
@hutchic
Copy link

hutchic commented Dec 13, 2021

have docs / examples by chance?

@shaneutt
Copy link
Contributor Author

have docs / examples by chance?

There's a helper doc present in the CLI which explains how to push images, but we definitely need to start thinking more holistically about documenting KTF now that our use cases are expanding beyond the KIC.

Here's an example run which includes that output:

$ go run cmd/ktf/main.go envs create --addon metallb --addon cert-manager --addon registry
building new environment kong-testing-environment
waiting for addon registry to become ready...
waiting for addon metallb to become ready...
waiting for addon cert-manager to become ready...
waiting for environment to become ready (this can take some time)...
environment kong-testing-environment was created successfully!

Registry Addon HELP:

You have installed the registry addon deployed with an SSL certificate provided
by cert-manager. The default certificate used is a self-signed certificate.
As such if you try to push images to this registry with the standard:

  $ docker push ${REGISTRY_IP}/image

Without first adding its certificate to your local docker (or other client) chain
of trust it will fail. The following provides an example of how to add the certificate
using a standard docker installation on a Linux system where "/etc/docker" is the
configuration directory for docker:

  $ REGISTRY_IP="$(kubectl -n registry get svc registry -o=go-template='{{(index .status.loadBalancer.ingress 0).ip}}')"
  $ sudo mkdir -p /etc/docker/certs.d/${REGISTRY_IP}/
  $ kubectl -n registry get secrets registry-cert-secret -o=go-template='{{index .data "ca.crt"}}' | base64 -d | sudo tee /etc/docker/certs.d/${REGISTRY_IP}/ca.crt

Note that this generally is not going to work verbatim on all systems and the
above instructions should be considered just an example. Adjust for your own
system and docker installation. You may also need to change ".ip" for ".host"
if your service is provided a DNS name instead of an IP for its LB address.

Afterwards you should be able to push images to the registry, e.g.:

  $ docker pull kennethreitz/httpbin
  $ docker tag kennethreitz/httpbin ${REGISTRY_IP}/httpbin
  $ docker push ${REGISTRY_IP}/httpbin

Images pushed this way should be immediately usable in pod configurations
on the cluster as the certificate is automatically configured on the nodes.

So the short version you'll need to trust the certificate in your local environment, and then whatever the LoadBalancer IP is for the registry you can use that to push images and you can configure your images in podspecs, e.g. image: <your lb ip>/<image>:<tag>.

So in my own environment, this is what I literally ran to push an image to the registry:

$ go run cmd/ktf/main.go envs create --addon metallb --addon cert-manager --addon registry
$ REGISTRY_IP="$(kubectl -n registry get svc registry -o=go-template='{{(index .status.loadBalancer.ingress 0).ip}}')"
$ sudo mkdir -p /etc/docker/certs.d/${REGISTRY_IP}/
$ kubectl -n registry get secrets registry-cert-secret -o=go-template='{{index .data "ca.crt"}}' | base64 -d | sudo tee /etc/docker/certs.d/${REGISTRY_IP}/ca.crt
$ docker pull nginx
$ docker tag nginx ${REGISTRY_IP}/nginx
$ docker push ${REGISTRY_IP}/nginx

Then used it for a deployment:

$ cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: ${REGISTRY_IP}/nginx
        ports:
        - containerPort: 80
EOF

And then:

$ kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-57f46f4d55-clbgf   1/1     Running   0          3s

Hopefully that helps you in the short term, for the long term I've created #184 so we can start improving the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/feature New feature or request priority/medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A registry addon
3 participants