spark_on_k8s.client¶
See the reference overview for supported entry points and task guides. A module may also contain helpers outside the documented public API.
ExecutorInstances
dataclass
¶
Number of executors to request
Attributes:
| Name | Type | Description |
|---|---|---|
min |
int | None
|
Minimum number of executors. If provided, dynamic allocation is enabled |
max |
int | None
|
Maximum number of executors. If provided, dynamic allocation is enabled |
initial |
int | None
|
Initial number of executors. If max and min are not provided, defaults to 2, dynamic allocation will be disabled and the number of executors will be fixed. |
executor_allocation_ratio |
float
|
Executor allocation ratio to use for dynamic allocation. Defaults to 1.0 |
scheduler_backlog_timeout |
str
|
Scheduler backlog timeout to use for dynamic allocation. Defaults to "1s" |
sustained_scheduler_backlog_timeout |
str | None
|
Sustained scheduler backlog timeout to use for dynamic allocation. Defaults to sustained_scheduler_backlog_timeout. |
Source code in spark_on_k8s/client.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
PodResources
dataclass
¶
Resources to request for the Spark driver and executors
Attributes:
| Name | Type | Description |
|---|---|---|
cpu |
int
|
Number of CPU cores to request |
memory |
int
|
Amount of memory to request in MB |
memory_overhead |
int
|
Amount of memory overhead to request in MB |
Source code in spark_on_k8s/client.py
51 52 53 54 55 56 57 58 59 60 61 62 63 | |
SparkAppWait
¶
Bases: str, Enum
Enum for the Spark app waiter options
Source code in spark_on_k8s/client.py
43 44 45 46 47 48 | |
SparkOnK8S
¶
Bases: LoggingMixin
Client for submitting Spark apps to Kubernetes
Examples:
>>> from spark_on_k8s.client import SparkOnK8S
>>> spark = SparkOnK8S()
>>> spark.submit_app(
... image="apache/spark:3.5.9-scala2.12-java17-python3-ubuntu",
... app_path="local:///opt/spark/examples/jars/spark-examples_2.12-3.5.9.jar",
... class_name="org.apache.spark.examples.SparkPi",
... app_name="spark-pi",
... app_arguments=["1000"],
... namespace="spark",
... service_account="spark",
... app_waiter="log",
... )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k8s_client_manager
|
KubernetesClientManager | None
|
Kubernetes client manager to use for creating Kubernetes clients |
None
|
logger_name
|
str | None
|
Name of the logger to use for logging, defaults to "SparkOnK8S" |
None
|
Source code in spark_on_k8s/client.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 | |
cancel_run(run, *, force=False)
¶
Request deletion of exactly the recorded driver; does not wait for cleanup.
Source code in spark_on_k8s/client.py
828 829 830 | |
connect_server_status(handle, *, timeout=10)
¶
Observe exactly the recorded server resources without importing PySpark.
Source code in spark_on_k8s/client.py
148 149 150 151 152 | |
create_connect_server(config)
¶
Create a private Spark Connect server; return identity before checking readiness.
Source code in spark_on_k8s/client.py
136 137 138 139 140 | |
delete_connect_server(handle, *, timeout=10)
¶
Request deletion only after validating all recorded server resource identities.
Source code in spark_on_k8s/client.py
175 176 177 178 179 | |
diagnose_app(*, namespace, app_id=None, pod_name=None, pod_limit=20, event_limit=100, timeout=10)
¶
Read bounded pod/event evidence without changing the application.
Source code in spark_on_k8s/client.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
doctor(*, namespace, service_account='spark', timeout=10)
¶
Check caller access and driver service-account existence without applying changes.
Source code in spark_on_k8s/client.py
242 243 244 245 246 247 248 249 | |
list_connect_servers(namespace, *, timeout=10)
¶
List drivers labeled as Connect servers in one namespace; read-only and label-based.
Source code in spark_on_k8s/client.py
154 155 156 157 158 | |
plan_app(**kwargs)
¶
Render a deterministic offline preview using the same builder as submission.
Source code in spark_on_k8s/client.py
879 880 881 882 883 884 885 886 | |
plan_connect_server(config)
¶
Preview a Connect server's resources offline; Secrets are shown only as references.
Source code in spark_on_k8s/client.py
142 143 144 145 146 | |
submit_app(*, image=NOTSET, app_path=NOTSET, namespace=NOTSET, service_account=NOTSET, app_name=NOTSET, spark_conf=NOTSET, class_name=NOTSET, packages=NOTSET, app_arguments=NOTSET, app_id_suffix=NOTSET, app_waiter=NOTSET, image_pull_policy=NOTSET, ui_reverse_proxy=NOTSET, driver_resources=NOTSET, executor_resources=NOTSET, executor_instances=NOTSET, should_print=NOTSET, secret_values=NOTSET, driver_ephemeral_configmaps_volumes=NOTSET, driver_env_vars_from_secrets=NOTSET, volumes=NOTSET, driver_volume_mounts=NOTSET, executor_volume_mounts=NOTSET, driver_node_selector=NOTSET, executor_node_selector=NOTSET, driver_annotations=NOTSET, executor_annotations=NOTSET, driver_labels=NOTSET, executor_labels=NOTSET, driver_tolerations=NOTSET, executor_pod_template_path=NOTSET, executor_pod_template=NOTSET, startup_timeout=NOTSET, wait_timeout=None, driver_init_containers=NOTSET, driver_host_aliases=NOTSET, driver_pod_template=None, driver_container_name=None, max_runtime=None, dry_run=False)
¶
Submit a Spark app to Kubernetes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str | ArgNotSet
|
Docker image to use for the Spark driver and executors |
NOTSET
|
app_path
|
str | ArgNotSet
|
Path to the application JAR / Python / R file |
NOTSET
|
namespace
|
str | ArgNotSet
|
Kubernetes namespace to use, defaults to "default" |
NOTSET
|
service_account
|
str | ArgNotSet
|
Kubernetes service account to use for the Spark driver, defaults to "spark" |
NOTSET
|
app_name
|
str | ArgNotSet
|
Name of the Spark application, defaults to a generated name as
|
NOTSET
|
spark_conf
|
dict[str, str] | ArgNotSet
|
Dictionary of spark configuration to pass to the application |
NOTSET
|
class_name
|
str | ArgNotSet
|
Name of the class to execute |
NOTSET
|
packages
|
list[str] | ArgNotSet
|
List of maven coordinates of jars to include in the classpath |
NOTSET
|
app_arguments
|
list[str] | ArgNotSet
|
List of arguments to pass to the application |
NOTSET
|
app_id_suffix
|
Callable[[], str] | ArgNotSet
|
Function to generate a suffix for the application ID, defaults to
|
NOTSET
|
app_waiter
|
Literal['no_wait', 'wait', 'log'] | ArgNotSet
|
How to wait for the app to finish. One of "no_wait", "wait", or "log" |
NOTSET
|
image_pull_policy
|
Literal['Always', 'Never', 'IfNotPresent'] | ArgNotSet
|
Image pull policy for the driver and executors, defaults to "IfNotPresent" |
NOTSET
|
ui_reverse_proxy
|
bool | ArgNotSet
|
Whether to use a reverse proxy for the Spark UI, defaults to False |
NOTSET
|
driver_resources
|
PodResources | ArgNotSet
|
Resources to request for the Spark driver. Defaults to 1 CPU core, 1Gi of memory and512Mi of memory overhead |
NOTSET
|
executor_resources
|
PodResources | ArgNotSet
|
Resources to request for the Spark executors. Defaults to 1 CPU core, 1Gi of memory and 512Mi of memory overhead |
NOTSET
|
executor_instances
|
ExecutorInstances | ArgNotSet
|
Number of executors to request. If max and min are not provided, dynamic allocation will be disabled and the number of executors will be fixed to initial or 2 if initial is not provided. If max or min or both are provided, dynamic allocation will be enabled and the number of executors will be between min and max (inclusive), and initial will be the initial number of executors with a default of 0. |
NOTSET
|
should_print
|
bool | ArgNotSet
|
Whether to print logs instead of logging them, defaults to False |
NOTSET
|
secret_values
|
dict[str, str] | ArgNotSet
|
Dictionary of secret values to pass to the application as environment variables |
NOTSET
|
driver_ephemeral_configmaps_volumes
|
list[ConfigMap] | ArgNotSet
|
List of ephemeral configmaps to create for the application driver |
NOTSET
|
driver_env_vars_from_secrets
|
list[str] | ArgNotSet
|
List of secret names to load environment variables from for the driver |
NOTSET
|
volumes
|
list[V1Volume] | ArgNotSet
|
List of volumes to mount to the driver and/or executors |
NOTSET
|
driver_volume_mounts
|
list[V1VolumeMount] | ArgNotSet
|
List of volume mounts to mount to the driver |
NOTSET
|
executor_volume_mounts
|
list[V1VolumeMount] | ArgNotSet
|
List of volume mounts to mount to the executors |
NOTSET
|
driver_node_selector
|
dict[str, str] | ArgNotSet
|
Node selector for the driver |
NOTSET
|
executor_node_selector
|
dict[str, str] | ArgNotSet
|
Node selector for the executors |
NOTSET
|
driver_tolerations
|
list[V1Toleration] | ArgNotSet
|
List of tolerations for the driver |
NOTSET
|
executor_pod_template_path
|
str | ArgNotSet
|
Path to the executor pod template file |
NOTSET
|
executor_pod_template
|
str | ArgNotSet
|
Executor pod template content as string or local file path. If provided, a ConfigMap will be created and mounted automatically |
NOTSET
|
startup_timeout
|
int | ArgNotSet
|
Timeout in seconds to wait for the application to start |
NOTSET
|
driver_init_containers
|
list[V1Container] | ArgNotSet
|
List of init containers to run before the driver starts |
NOTSET
|
driver_host_aliases
|
list[V1HostAlias] | ArgNotSet
|
List of host aliases for the driver |
NOTSET
|
driver_pod_template
|
str | Path | Mapping[str, Any] | None
|
Driver Pod YAML text, a local file path, or a mapping. Generated identity and launch settings override the template; other fields are preserved. |
None
|
driver_container_name
|
str | None
|
Container to use as the driver in the template. Defaults to the container named "driver", or the sole container. Ambiguous templates are rejected. |
None
|
max_runtime
|
int | None
|
Maximum driver lifetime in whole seconds, set as the driver pod's
|
None
|
dry_run
|
bool
|
Build an offline plan without opening a Kubernetes connection or creating resources. |
False
|
Returns:
| Type | Description |
|---|---|
str | ApplicationPlan
|
Name of the Spark application pod. The same identity is available as last_submitted_run. |
The optional wait_timeout bounds observation after resource creation, in seconds. It does not stop or delete the application. None preserves unlimited waiting.
Source code in spark_on_k8s/client.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
submit_run(**kwargs)
¶
Submit using the same arguments as submit_app, returning a structured run identity.
Source code in spark_on_k8s/client.py
127 128 129 130 131 132 133 134 | |
submit_sql(*, sql=None, sql_file=None, **submit_options)
¶
Submit inline SQL or a local SQL file using a PySpark image.
Exactly one of sql and sql_file is required. Other keyword arguments
are passed to :meth:submit_app, including image, resources, namespace,
service account, packages, and waiter options. SQL runs in statement order;
the first failed statement fails the application. This is not a transaction.
Set dry_run=True to return an offline :class:ApplicationPlan instead of submitting.
Source code in spark_on_k8s/client.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
wait_connect_server_ready(handle, *, profile, timeout=60, poll_interval=1)
¶
Verify a real Connect query, remote application identity and current resource UIDs.
Source code in spark_on_k8s/client.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
default_app_id_suffix()
¶
Default function to generate a suffix for the application ID
Returns:
| Type | Description |
|---|---|
str
|
the current UTC timestamp in the format %Y%m%d%H%M%S prefixed with a dash (e.g. -20240101123456) |
Source code in spark_on_k8s/client.py
32 33 34 35 36 37 38 39 | |