java icon indicating copy to clipboard operation
java copied to clipboard

Need a pointer/ example on how to do `kubectl -f apply abc.yaml`

Open ravieze opened this issue 2 years ago • 6 comments
trafficstars

Describe the bug I went through the examples but I was unable to figure out how to simulate kubectrl -f apply abc.yaml

I am using spark operator. The yaml is of kind SparkApplication. I was able to find a way to submit svc and pods to the kubernetis. But I was not able to figure out how to submit a custom yaml which submits to spark operator

Client Version latest

Kubernetes Version 1.25.4

Java Version Java 8

To Reproduce Steps to reproduce the behavior:

Expected behavior A clear and concise description of what you expected to happen.

KubeConfig If applicable, add a KubeConfig file with secrets redacted.

Server (please complete the following information):

  • OS: [e.g. Linux] -- ARM LInux
  • Environment [e.g. container] - DOcker
  • Cloud [e.g. Azure] - AWS EKS

Additional context Add any other context about the problem here.

ravieze avatar May 24 '23 14:05 ravieze

You need to generate or write a pojo (Java Object) that represents your SparkApplication, once you do that you can use it with the KubectlApply code here: https://github.com/kubernetes-client/java/blob/master/extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlApply.java

Alternately, you can use the generic client: https://github.com/kubernetes-client/java/blob/master/examples/examples-release-15/src/main/java/io/kubernetes/client/examples/GenericClientExample.java

It's not quite KubectlApply but it enables you to create arbitrary resources without defining a Java object.

brendandburns avatar May 24 '23 21:05 brendandburns

May be below link would help kubectl-apply

tamilselvan1102 avatar May 30 '23 11:05 tamilselvan1102

This was what I was looking out for. But even before your advice, this is what I did...

kc apply -f /tmp/Sparkapplication.yaml --v=8 --server-side

This returns the list of REST APIs being called by kubectl. I found doing this way is way is easy and simple.

The generic client is given -- I was not able to figure out how to get the same done easily. SO i took the above approach.

ravieze avatar Jun 01 '23 04:06 ravieze

You can load the yaml and use Kubectl.apply to create it : )

        String yamlContent = "";
        String namespace = "";

        ApiClient client = Config.fromCluster();
        List<Object> k8sObjects = Yaml.loadAll(yamlContent);
        for (Object object : k8sObjects) {
            Kubectl.apply(KubernetesObject.class)
                .apiClient(client)
                .namespace(namespace)
                .resource((KubernetesObject) object)
                .execute();
        }

simsnow avatar Aug 03 '23 10:08 simsnow

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jan 25 '24 18:01 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Feb 24 '24 19:02 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Mar 25 '24 20:03 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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 avatar Mar 25 '24 20:03 k8s-ci-robot