I am creating a deployment using deployment.yaml file below with version 15.0.1 (Current Latest)
apiVersion: apps/v1
kind: Deployment
metadata:
name: demoapp-sample
spec:
selector:
matchLabels:
app: demoapp-sample
replicas: 1
template:
metadata:
labels:
app: demoapp-sample
spec:
containers:
- name: demoapp
image: test/demoapp
# Image that will be used to containers in the cluster
imagePullPolicy: Always
ports:
- containerPort: 9005
# The port that the container is running on in the cluster
My java code is, in which resourceFile object has the deployment.yaml content:
try {
ApiClient client = ClientBuilder.cluster().build();
Configuration.setDefaultApiClient(client);
AppsV1Api api = new AppsV1Api();
V1Deployment yamlDeployment = (V1Deployment) Yaml.load(new InputStreamReader(resourceFile.getInputStream()));
V1Deployment createResult = api.createNamespacedDeployment("default", yamlDeployment, null, null, null, null);
System.out.println(createResult);
return "Deployment created successfully.";
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
My cluster-role.yaml file for the container running the above code is:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
# "namespace" omitted since ClusterRoles are not namespaced
name: demo-cluster-role
rules:
- apiGroups: ["","apps"]
resources: ["pods","deployments","services"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
So I have permissions to create the deployments. But when I run this code, Im getting exception as
Unknown apiVersionKind apps/v1/Deployment is it registered?
How can I resolve this issue?
I am creating a deployment using deployment.yaml file below with version 15.0.1 (Current Latest)
My java code is, in which resourceFile object has the deployment.yaml content:
My cluster-role.yaml file for the container running the above code is:
So I have permissions to create the deployments. But when I run this code, Im getting exception as
Unknown apiVersionKind apps/v1/Deployment is it registered?How can I resolve this issue?