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

How to run kubernetes e2e tests with kind and upgrade the cluster components with your local changes #1181

Open
aojea opened this issue Dec 18, 2019 · 28 comments
Assignees
Labels
kind/documentation Categorizes issue or PR as related to documentation. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Milestone

Comments

@aojea
Copy link
Contributor

aojea commented Dec 18, 2019

What would you like to be documented:

How to use kind to test your code with e2e tests

Why is this needed:

I know that Ben has this in the backlog, that there are several nice tutorials and videos, there is also a script in the repo to execute the e2e tests, ..., but I always fall back to my snippet :-)

@aojea aojea added the kind/documentation Categorizes issue or PR as related to documentation. label Dec 18, 2019
@aojea
Copy link
Contributor Author

aojea commented Dec 18, 2019

More complete instructions here

https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md#running-conformance-tests

This is how I do it :

  1. Work in your kubernetes branch, preferably in the default go src location

  2. Create your kind node image:
    kind build node-image

  3. Create your kind e2e cluster config kind-config-yaml:

# necessary for conformance
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  ipFamily: ipv4
nodes:
# the control plane node
- role: control-plane
- role: worker
- role: worker

  1. Set your KUBECONFIG env variable (KIND generates the conf based on it):
    export KUBECONFIG="${HOME}/.kube/kind-test-config"

  2. Use the previous config to create your cluster:
    kind create cluster --config kind-config.yaml --image kindest/node:latest -v4

  3. Create your e2e Kubernetes binary (from your Kubernetes src code):
    make WHAT="test/e2e/e2e.test"

  4. Execute your tests:
    ./_output/bin/e2e.test -context kind-kind -ginkgo.focus="\[sig-network\].*Conformance" -num-nodes 2

Note: updated with new KIND features and known issues

@BenTheElder
Copy link
Member

@mauilion
also #986

@aojea
Copy link
Contributor Author

aojea commented Jan 14, 2020

To expand on this and for completenes, let's say that you have a change in kube-proxy, you don't have to redo all the steps, you just need to:

  • build the new image:

bazel build //build:docker-artifacts

  • load it in your current kind cluster:

kind load image-archive bazel-bin/build/kube-proxy.tar

  • check that it has been loaded:
docker exec -it kind-control-plane crictl images
IMAGE                                      TAG                                        IMAGE ID            SIZE
docker.io/kindest/kindnetd                 0.5.4                                      2186a1a396deb       113MB
docker.io/rancher/local-path-provisioner   v0.0.11                                    9d12f9848b99f       36.5MB
k8s.gcr.io/coredns                         1.6.5                                      70f311871ae12       41.7MB
k8s.gcr.io/debian-base                     v2.0.0                                     9bd6154724425       53.9MB
k8s.gcr.io/etcd                            3.4.3-0                                    303ce5db0e90d       290MB
k8s.gcr.io/kube-apiserver                  v1.17.0                                    4a0e3a87a5e22       144MB
k8s.gcr.io/kube-controller-manager         v1.17.0                                    fa313a582b872       131MB
k8s.gcr.io/kube-proxy-amd64                v1.18.0-alpha.1.633_8428af6fd79e1f-dirty   5dd06b2bb1290       124MB
k8s.gcr.io/kube-proxy                      v1.17.0                                    e3dd0e2bea53a       132MB
k8s.gcr.io/kube-scheduler                  v1.17.0                                    cb8feb1d83dd3       112MB
k8s.gcr.io/pause                           3.1                                        da86e6ba6ca19       746kB
  • and modify the kubernetes deployment to pick the new image, in this case you can follow these instructions to switch the container image of the daemonset

https://kubernetes.io/docs/tasks/manage-daemon/update-daemon-set/

@BenTheElder
Copy link
Member

To expand on this and for completenes, let's say that you have a change in kube-proxy, you don't have to redo all the steps, you just need to:

for that kind of power user, you can do this today and write yourself a small script.

at the moment I'm specifically focused on #986 which is about mimicing the kubernetes flow.

if you're building with bazel you already no-op most of the build if you didn't change the other binaries, I wouldn't recommend taking shortcuts vs just running a node image build.

@aojea
Copy link
Contributor Author

aojea commented Jan 15, 2020

yeah, you are absolutely right.
I'm just sharing some experiences, specifically, this last case I've added is useful when you are doing some exploratory analysis on a complex setup and/or your prototyping something.

@Rand01ph
Copy link

@aojea Thank you for your share. I try your snippet, but the test blocked with INFO: Running AfterSuite actions on all nodes. It's all right ?

@aojea
Copy link
Contributor Author

aojea commented Jan 29, 2020

@aojea Thank you for your share. I try your snippet, but the test blocked with INFO: Running AfterSuite actions on all nodes. It's all right ?

nope, it has to run the test suite and show the results ... :/

@benthelder is working in improving the UX #986

@Rand01ph
Copy link

@aojea Yes, it has run the test suite and show the results, but the process is not end itself, after tests, it blocked with INFO: Running AfterSuite actions on all nodes

@BenTheElder
Copy link
Member

BenTheElder commented Jan 31, 2020 via email

@Rand01ph
Copy link

Rand01ph commented Feb 5, 2020

@BenTheElder I just use the bazel-bin/test/e2e/e2e.test -context kind-kind -ginkgo.focus="\[sig-network\].*Conformance" -num-nodes 2 -ginkgo.parallel.total 8

@aojea
Copy link
Contributor Author

aojea commented Feb 5, 2020

naive question, do you have at least 2 workers in your cluster?

@Rand01ph
Copy link

Rand01ph commented Feb 5, 2020

naive question, do you have at least 2 workers in your cluster?

Yes, i follow your steps. The test can be run, but it does not end by itself

@BenTheElder
Copy link
Member

I'm not certain about that invocation, currently we use hack/ginkgo-e2e.sh in k8s which handles a few more things, you can check our own hack/ci dir for the current scripts we use to do this, they set some other things

@aojea
Copy link
Contributor Author

aojea commented Feb 5, 2020

in parallel, I'll check if I have some additional environment variables that are missing causing this behavior.

@aojea
Copy link
Contributor Author

aojea commented Feb 10, 2020

@Rand01ph I hit the same issue, it seems related to skewed versions between the node image and the e2e.test binary :/

Feb 10 14:26:40.322: INFO: e2e test version: v1.18.0-alpha.2.580+acd97b42f3acb0
Feb 10 14:26:40.323: INFO: kube-apiserver version: v1.17.0

the solution is to remove the -ginkgo.parallel.total 8 , there are more issues referring to this behavior

onsi/ginkgo#206

@BenTheElder
Copy link
Member

that sounds like a bug in e2e.test ...

@RainbowMango
Copy link
Member

RainbowMango commented Feb 14, 2020

Can we use kind to run conformance tests with a specific CCM(cloud controller manager)?

In that case, we need to custom some components, such as:

  • set kube-apiserver/kube-controller-manager with flags --cloud-provider=external
  • set kubelet with flags --cloud-provider=openstack or gcp
  • start an extra CCM. (This can be done by running the CCM container in the kind cluster, right?)

@BenTheElder Can you share your comments? I'm just starting to use kind, after went through the relative document, I'm not sure if kind support this case.

@MHBauer
Copy link

MHBauer commented Jun 1, 2020

Since this has such a great title, can we share some of the links to the other tutorials and videos that exist?

@BenTheElder
Copy link
Member

@MHBauer check out https://kind.sigs.k8s.io/docs/user/resources/

@RainbowMango maybe, CCMs have their own requirements, it's not something we're doing currently. I'm aware of some third party work in the past with the vsphere CCM and a vsphere fake + kind

sorry the integrated test work has gone so slowly, we keep having to paper over the existing tests, right now we're dealing with multiple critical bugs before daring to change the test workflow.

@MHBauer
Copy link

MHBauer commented Jun 2, 2020 via email

@aojea aojea changed the title How to run kubernetes e2e tests with kind How to run kubernetes e2e tests with kind and upgrade the cluster components with your local changes Oct 21, 2020
@aojea
Copy link
Contributor Author

aojea commented Oct 21, 2020

@BenTheElder I've created a script to upgrade the cluster components with the kubernetes repo local changes

https://gist.github.com/aojea/2c94034f8e86d08842e5916231eb3fe1

I wanted to add them to kind using a kind upgrade <component> <node> command or something similar, but I think that you have already something in mind so I prefer to sync with you first.

I'm sure this will boost development productivity

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 19, 2021
@BenTheElder BenTheElder removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 25, 2021
@BenTheElder BenTheElder modified the milestones: v0.10.0, v0.12.0 Jan 25, 2021
@BenTheElder
Copy link
Member

I think maybe we should just add a user guide page for this and it can eventually reference the shinier guide we want later. Even just a basic pointer to what the shell scripts we have now do / what CI is doing is probably worth getting a rough page up for sooner rather than later.

@BenTheElder BenTheElder modified the milestones: v0.12.0, v0.11.0 Jan 25, 2021
@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 25, 2021
@kubernetes-sigs kubernetes-sigs deleted a comment from fejta-bot Apr 27, 2021
@BenTheElder BenTheElder added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Apr 27, 2021
@BenTheElder BenTheElder modified the milestones: v0.11.0, 1.0 Oct 14, 2021
@uablrek
Copy link

uablrek commented Jun 3, 2023

the solution is to remove the -ginkgo.parallel.total 8 , there are more issues referring to this behavior

What is the correct way, or best practice, to run tests in parallel?

I have got excellent advice from @aojea in the past (thanks!) that I am still using so, I have done:

#go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo  # once
e2e=$GOPATH/src/k8s.io/kubernetes/_output/bin/e2e.test
FOCUS="\[sig-network\].*Conformance"
ginkgo --nodes=16 --focus="${FOCUS}" $e2e -- --num-nodes=2 --provider=skeleton

and got execution time down by ~7 times (>500s -> ~75s).

@aojea
Copy link
Contributor Author

aojea commented Jun 4, 2023

@uablrek
Copy link

uablrek commented Jun 5, 2023

Man, you seem to have a gist for everything 😄 Thanks. I think it might be the same advise I got years back

@YuikoTakada
Copy link

This information is documented somewhere?

@BenTheElder
Copy link
Member

This is a bit of a hack, but the gist linked above is the approach.

Otherwise the general full approach is to 1) kind build node-image and then create the cluster with that image, and then run the tests as normal like any conformant cluster, we also have scripts for that in this repo, and Kubernetes contributors can see them running on their PRs (e.g. pull-kubernetes-e2e-kind, see the logs which log exactly what is run).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Development

No branches or pull requests

9 participants