Package io.kubernetes.client.examples
Class ExpandedExample
java.lang.Object
io.kubernetes.client.examples.ExpandedExample
A simple example of how to use the Java API
Easiest way to run this: mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.ExpandedExample"
From inside $REPO_DIR/examples
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet all namespaces in k8s clusterList all pod in the default namespacegetNamespacedPod(String namespace) List pod in specific namespacegetNamespacedPod(String namespace, String label) List pod in specific namespace with labelgetPods()List all pod names in all namespaces in k8s clusterList all Services in default namespacestatic voidMain methodstatic voidPrint out the Log for specific Podsstatic voidscaleDeployment(String deploymentName, int numberOfReplicas) Scale up/down the number of pod in Deployment
-
Constructor Details
-
ExpandedExample
public ExpandedExample()
-
-
Method Details
-
main
Main method- Parameters:
args-
-
getAllNameSpaces
Get all namespaces in k8s cluster- Returns:
- Throws:
io.kubernetes.client.openapi.ApiException
-
getPods
List all pod names in all namespaces in k8s cluster- Returns:
- Throws:
io.kubernetes.client.openapi.ApiException
-
getNamespacedPod
List all pod in the default namespace- Returns:
- Throws:
io.kubernetes.client.openapi.ApiException
-
getNamespacedPod
public static List<String> getNamespacedPod(String namespace) throws io.kubernetes.client.openapi.ApiException List pod in specific namespace- Parameters:
namespace-- Returns:
- Throws:
io.kubernetes.client.openapi.ApiException
-
getNamespacedPod
public static List<String> getNamespacedPod(String namespace, String label) throws io.kubernetes.client.openapi.ApiException List pod in specific namespace with label- Parameters:
namespace-label-- Returns:
- Throws:
io.kubernetes.client.openapi.ApiException
-
getServices
List all Services in default namespace- Returns:
- Throws:
io.kubernetes.client.openapi.ApiException
-
scaleDeployment
public static void scaleDeployment(String deploymentName, int numberOfReplicas) throws io.kubernetes.client.openapi.ApiException Scale up/down the number of pod in Deployment- Parameters:
deploymentName-numberOfReplicas-- Throws:
io.kubernetes.client.openapi.ApiException
-
printLog
public static void printLog(String namespace, String podName) throws io.kubernetes.client.openapi.ApiException Print out the Log for specific Pods- Parameters:
namespace-podName-- Throws:
io.kubernetes.client.openapi.ApiException
-