java
java copied to clipboard
Need a pointer/ example on how to do `kubectl -f apply abc.yaml`
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.
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.
May be below link would help kubectl-apply
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.
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();
}
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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: 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/staleis applied- After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied- After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closedYou 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.