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

Add auto-deploy custom manifest support #2991

Closed
wants to merge 4 commits into from

Conversation

datachi7d
Copy link

This adds the ability to do a one-shot deploy manifests on startup of a kind cluster, for example setting up an ingress NGINX in the User guide would become:

cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  extraPortMappings:
  - containerPort: 80
    hostPort: 80
    protocol: TCP
  - containerPort: 443
    hostPort: 443
    protocol: TCP

customManifests:
  - https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
EOF

The customManifests supports local files, http/s URLs and inline yaml, for example:

customManifests:
  - path/to/local/file.yaml
  - https://projectcontour.io/quickstart/contour.yaml
  - inline.yaml: |
      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - name: nginx
          image: nginx:1.14.2
          ports:
          - containerPort: 80

The functionality is similar to the likes of auto-deploying manifests in k3s or k0s, however these appear to use controllers to continuously monitor the manifests for changes and reconcile those changes.

I have seen #253 which relies on kubeadm to deploy/manage "addons", but as far as I can tell there has been no progress in this area.

So this one way to deploy custom manifests on startup, the alternative implementations could be:

  • kubeadm supports managing/deploying addons via yaml manifests
  • static pod that implements a controller to reconcile a manifests directory, similar to k3s/k0s

Looking forward to any feedback on this :)

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 4, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Nov 4, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: datachi7d
Once this PR has been reviewed and has the lgtm label, please assign aojea for approval by writing /assign @aojea in a comment. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Contributor

Welcome @datachi7d!

It looks like this is your first PR to kubernetes-sigs/kind 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kind has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @datachi7d. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 4, 2022
@datachi7d
Copy link
Author

Found a few problems with a simple pod example:

$ cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4


customManifests:
  - inline.yaml: |
      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - name: nginx
          image: nginx:1.14.2
          ports:
          - containerPort: 80
EOF
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.25.3) 🖼
 ✓ Preparing nodes 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✗ Installing custom manifests 📃 
ERROR: failed to create cluster: failed to add default storage class: customManifest[0][inline.yaml]: command "docker exec --privileged -i kind-control-plane kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f -" failed with error: exit status 1

Firstly error message isn't too helpful here, and secondly it appears that in this case it is failing to create the pod due to the default service account not being present.

I will take a look into moving the action to after waitforready and adding stdout from kubectl to the error message.

@datachi7d
Copy link
Author

Looks like the error wasn't wrapped correctly, so now the kubectl output is being printed:

$ cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4

customManifests:
  - inline.yaml: |
      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - name: nginx
          image: nginx:1.14.2
          ports:
          - containerPort: 80
EOF
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.25.3) 🖼
 ✓ Preparing nodes 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✗ Installing custom manifests 📃 
ERROR: failed to create cluster: failed to deploy manifest: customManifest[0][inline.yaml]: error deploying manifest: command "docker exec --privileged -i kind-control-plane kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f -" failed with error: exit status 1
Command Output: Error from server (Forbidden): error when creating "STDIN": pods "nginx" is forbidden: error looking up service account default/default: serviceaccount "default" not found

To resolve the service account problem I moved the action so that it's after waitforready, but that means it requires the user to specify a wait:

$ cat <<EOF | kind create cluster --wait 30s --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4

customManifests:
  - inline.yaml: |
      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - name: nginx
          image: nginx:1.14.2
          ports:             
          - containerPort: 80
EOF                          
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.25.3) 🖼
 ✓ Preparing nodes 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✓ Waiting ≤ 30s for control-plane = Ready ⏳ 
 • Ready after 18s 💚
 ✓ Installing custom manifests 📃 
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Thanks for using kind! 😊
$ kubectl get pods
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          20s

} else {
// read file in
var manifest []byte
if manifest, err = os.ReadFile(t); os.IsNotExist(err) {
Copy link
Author

Choose a reason for hiding this comment

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

This is going to pickup files relative to the cwd - should it be relative to the cluster configuration yaml path (when not given via stdin)?

@BenTheElder
Copy link
Member

I'm sorry, but per our contributing guide features should be discussed as an issue first https://kind.sigs.k8s.io/docs/contributing/getting-started/#4-reaching-out

Initial feedback: This is a feature that can grow complex very quickly yet simple versions can be easily implemented outside of kind. It is unclear that we should build this in. For example, users will then want to support various forms of templating, dependency ordering and error handling, etc. But you can already do this by kind create cluster && kubectl apply

@BenTheElder
Copy link
Member

The kubernetes ecosystem has a plethora of tools whose sole purpose is managing manifests.

@aojea
Copy link
Contributor

aojea commented Nov 8, 2022

agree with Ben, I´d like Kind to be decoupled from the provisioning and keep doing what it does best, providing a kubernetes cluster

@datachi7d
Copy link
Author

Yes I can see how this would simplicate kind, or add feature bloat. Especially compared to user just creating a shell script that uses kind, kubectl, or helm. Having thought it through, I'm convinced auto deploying manifests isn't in the remit for kind.

@BenTheElder - I can create an issue for posterity?

@datachi7d datachi7d closed this Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants