Merge branch 'main' of github.com:rancher/k3d into enhancement/host-ip

pull/360/head
iwilltry42 4 years ago
commit a51063966f
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 2
      Dockerfile
  2. 7
      Makefile
  3. 4
      cmd/cluster/clusterCreate.go
  4. 6
      docs/usage/guides/exposing_services.md
  5. 4
      docs/usage/guides/registries.md
  6. 9
      tests/test_full_lifecycle.sh

@ -4,7 +4,7 @@ COPY . .
RUN make build && bin/k3d version
FROM docker:19.03-dind as dind
RUN apk add bash curl sudo jq git make
RUN apk update && apk add bash curl sudo jq git make netcat-openbsd
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl && \
chmod +x ./kubectl && \
mv ./kubectl /usr/local/bin/kubectl

@ -54,7 +54,7 @@ TARGET_OBJS ?= darwin-amd64.tar.gz darwin-amd64.tar.gz.sha256 linux-amd64.tar.gz
GO ?= go
PKG := $(shell go mod vendor)
TAGS :=
TESTS := .
TESTS := ./...
TESTFLAGS :=
LDFLAGS := -w -s -X github.com/rancher/k3d/v3/version.Version=${GIT_TAG} -X github.com/rancher/k3d/v3/version.K3sVersion=${K3S_TAG}
GCFLAGS :=
@ -151,6 +151,9 @@ check: check-fmt lint
########## Tests ##########
###########################
test:
$(GO) test $(TESTS) $(TESTFLAGS)
e2e: build-docker-dind
@echo "Running e2e tests in k3d:$(K3D_IMAGE_TAG)"
LOG_LEVEL="$(E2E_LOG_LEVEL)" E2E_SKIP="$(E2E_SKIP)" E2E_EXTRA="$(E2E_EXTRA)" E2E_RUNNER_START_TIMEOUT=$(E2E_RUNNER_START_TIMEOUT) tests/dind.sh "${K3D_IMAGE_TAG}-dind"
@ -199,7 +202,7 @@ endif
ci-setup:
@echo "Installing Go tools..."
curl -sfL $(PKG_GOLANGCI_LINT_SCRIPT) | sh -s -- -b ${GOPATH}/bin v$(PKG_GOLANGCI_LINT_VERSION)
go get $(PKG_GOX)
$(GO) get $(PKG_GOX)
@echo "Installing kubectl..."
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

@ -126,8 +126,8 @@ func NewCmdClusterCreate() *cobra.Command {
cmd.Flags().StringP("image", "i", fmt.Sprintf("%s:%s", k3d.DefaultK3sImageRepo, version.GetK3sVersion(false)), "Specify k3s image that you want to use for the nodes")
cmd.Flags().String("network", "", "Join an existing network")
cmd.Flags().String("token", "", "Specify a cluster token. By default, we generate one.")
cmd.Flags().StringArrayP("volume", "v", nil, "Mount volumes into the nodes (Format: `[SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]`\n - Example: `k3d cluster create --agents 2 -v /my/path@agent[0,1] -v /tmp/test:/tmp/other@server[0]`")
cmd.Flags().StringArrayP("port", "p", nil, "Map ports from the node containers to the host (Format: `[HOST:][HOSTPORT:]CONTAINERPORT[/PROTOCOL][@NODEFILTER]`)\n - Example: `k3d cluster create --agents 2 -p 8080:80@agent[0] -p 8081@agent[1]`")
cmd.Flags().StringArrayP("volume", "v", nil, "Mount volumes into the nodes (Format: `[SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]`\n - Example: `k3d cluster create --agents 2 -v \"/my/path@agent[0,1]\" -v \"/tmp/test:/tmp/other@server[0]\"`")
cmd.Flags().StringArrayP("port", "p", nil, "Map ports from the node containers to the host (Format: `[HOST:][HOSTPORT:]CONTAINERPORT[/PROTOCOL][@NODEFILTER]`)\n - Example: `k3d cluster create --agents 2 -p \"8080:80@agent[0]\" -p \"8081@agent[1]\"`")
cmd.Flags().BoolVar(&createClusterOpts.WaitForServer, "wait", true, "Wait for the server(s) to be ready before returning. Use '--timeout DURATION' to not wait forever.")
cmd.Flags().DurationVar(&createClusterOpts.Timeout, "timeout", 0*time.Second, "Rollback changes if cluster couldn't be created in specified duration.")
cmd.Flags().BoolVar(&updateDefaultKubeconfig, "update-default-kubeconfig", true, "Directly update the default kubeconfig with the new cluster's context")

@ -7,7 +7,7 @@ Therefore, we have to create the cluster in a way, that the internal port 80 (wh
1. Create a cluster, mapping the ingress port 80 to localhost:8081
`#!bash k3d cluster create --api-port 6550 -p 8081:80@loadbalancer --agents 2`
`#!bash k3d cluster create --api-port 6550 -p "8081:80@loadbalancer" --agents 2`
!!! info "Good to know"
- `--api-port 6550` is not required for the example to work. It's used to have `k3s`'s API-Server listening on port 6550 with that port mapped to the host system.
@ -56,11 +56,11 @@ Therefore, we have to create the cluster in a way, that the internal port 80 (wh
1. Create a cluster, mapping the port 30080 from agent-0 to localhost:8082
`#!bash k3d cluster create mycluster -p 8082:30080@agent[0] --agents 2`
`#!bash k3d cluster create mycluster -p "8082:30080@agent[0]" --agents 2`
- **Note**: Kubernetes' default NodePort range is [`30000-32767`](https://kubernetes.io/docs/concepts/services-networking/service/#nodeport)
- **Note**: You may as well expose the whole NodePort range from the very beginning, e.g. via `k3d cluster create mycluster --agents 3 -p 30000-32767:30000-32767@server[0]` (See [this video from @portainer](https://www.youtube.com/watch?v=5HaU6338lAk))
- **Note**: You may as well expose the whole NodePort range from the very beginning, e.g. via `k3d cluster create mycluster --agents 3 -p "30000-32767:30000-32767@server[0]"` (See [this video from @portainer](https://www.youtube.com/watch?v=5HaU6338lAk))
... (Steps 2 and 3 like above) ...

@ -3,7 +3,7 @@
## Registries configuration file
You can add registries by specifying them in a `registries.yaml` and mounting them at creation time:
`#!bash k3d cluster create mycluster --volume /home/YOU/my-registries.yaml:/etc/rancher/k3s/registries.yaml`.
`#!bash k3d cluster create mycluster --volume "/home/YOU/my-registries.yaml:/etc/rancher/k3s/registries.yaml"`.
This file is a regular [k3s registries configuration file](https://rancher.com/docs/k3s/latest/en/installation/private-registry/), and looks like this:
@ -61,7 +61,7 @@ configs:
Finally, we can create the cluster, mounting the CA file in the path we specified in `ca_file`:
`#!bash k3d cluster create --volume ${HOME}/.k3d/my-registries.yaml:/etc/rancher/k3s/registries.yaml --volume ${HOME}/.k3d/my-company-root.pem:/etc/ssl/certs/my-company-root.pem`
`#!bash k3d cluster create --volume "${HOME}/.k3d/my-registries.yaml:/etc/rancher/k3s/registries.yaml" --volume "${HOME}/.k3d/my-company-root.pem:/etc/ssl/certs/my-company-root.pem"`
## Using a local registry

@ -46,11 +46,18 @@ info "Checking that we have 3 nodes available now..."
check_multi_node "$clustername" 3 || failed "failed to verify number of nodes"
# 4. load an image into the cluster
info "Loading an image into the cluster..."
info "Importing an image into the cluster..."
docker pull nginx:latest > /dev/null
docker tag nginx:latest nginx:local > /dev/null
$EXE image import nginx:local -c $clustername || failed "could not import image in $clustername"
# 5. use that image
info "Spawning a pod using the imported image..."
kubectl run --image nginx:local testimage
info "Waiting for a bit for the pod to start..."
sleep 5
kubectl get pod testimage | grep 'Running' || failed "Pod using the imported image is not running after 5 seconds"
# Cleanup
info "Deleting cluster $clustername..."

Loading…
Cancel
Save