Skip to content

Commit

Permalink
add: registry proxy settings in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Jun 7, 2022
1 parent 0e821a4 commit 441c452
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 1 deletion.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
### Added

- Support for pull-through registry (#1075)
- In command `k3d registry create`
- e.g. `k3d registry create --proxy-remote-url https://registry-1.docker.io -p 5000 -v /tmp/registry:/var/lib/registry`
- In config file:

```yaml
# ...
registries:
create:
name: docker-io # name of the registry container
proxy:
remoteURL: https://registry-1.docker.io # proxy DockerHub
volumes:
- /tmp/reg:/var/lib/registry # persist data locally in /tmp/reg
config: | # tell K3s to use this registry when pulling from DockerHub
mirrors:
"docker.io":
endpoint:
- http://docker-io:5000
```
- See registry documentation
## v5.4.2 - 04.06.2022
Expand Down
6 changes: 6 additions & 0 deletions docs/usage/configfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ registries: # define how registries should be created or used
name: registry.localhost
host: "0.0.0.0"
hostPort: "5000"
proxy: # omit this to have a "normal" registry, set this to create a registry proxy (pull-through cache)
remoteURL: https://registry-1.docker.io # mirror the DockerHub registry
username: "" # unauthenticated
password: "" # unauthenticated
volumes:
- /some/path:/var/lib/registry # persist registry data locally
use:
- k3d-myotherregistry:5000 # some other k3d-managed registry; same as `--registry-use 'k3d-myotherregistry:5000'`
config: | # define contents of the `registries.yaml` file (or reference a file); same as `--registry-config /path/to/config.yaml`
Expand Down
29 changes: 29 additions & 0 deletions docs/usage/registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,32 @@ Then you should check that the pod is running with `kubectl get pods -l "app=ngi
```bash
k3d cluster create cluster02 --registry-use k3d-docker-io:5000 --registry-config registry.yml
```

### Creating a registry proxy / pull-through registry via configfile

1. Create a config file, e.g. `/home/me/test-regcache.yaml`

```yaml
apiVersion: k3d.io/v1alpha4
kind: Simple
metadata:
name: test-regcache
registries:
create:
name: docker-io # name of the registry container
proxy:
remoteURL: https://registry-1.docker.io # proxy DockerHub
volumes:
- /tmp/reg:/var/lib/registry # persist data locally in /tmp/reg
config: | # tell K3s to use this registry when pulling from DockerHub
mirrors:
"docker.io":
endpoint:
- http://docker-io:5000
```

2. Create cluster from config:

```bash
k3d cluster create -c /home/me/test-regcache.yaml
```
4 changes: 4 additions & 0 deletions pkg/config/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
Host: regName,
Image: image,
ExposureOpts: *regPort,
Volumes: simpleConfig.Registries.Create.Volumes,
Options: k3d.RegistryOptions{
Proxy: simpleConfig.Registries.Create.Proxy,
},
}
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/config/v1alpha4/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,17 @@
"password": {
"type": "string"
}
}
},
"additionalProperties": false
},
"volumes": {
"type": "array",
"items": {
"type": "string"
},
"examples": [
"/tmp/registry:/var/lib/registry"
]
}
},
"additionalProperties": false
Expand Down
1 change: 1 addition & 0 deletions pkg/config/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type SimpleConfigRegistryCreateConfig struct {
HostPort string `mapstructure:"hostPort" yaml:"hostPort,omitempty" json:"hostPort,omitempty"`
Image string `mapstructure:"image" yaml:"image,omitempty" json:"image,omitempty"`
Proxy k3d.RegistryProxy `mapstructure:"proxy" yaml:"proxy,omitempty" json:"proxy,omitempty"`
Volumes []string `mapstructure:"volumes" yaml:"volumes,omitempty" json:"volumes,omitempty"`
}

// SimpleConfigOptionsKubeconfig describes the set of options referring to the kubeconfig during cluster creation.
Expand Down

0 comments on commit 441c452

Please sign in to comment.