1. circleci/kubernetes@1.3.1

circleci/kubernetes@1.3.1

Certified
Sections
A collection of tools for working with Kubernetes on CircleCI View this orb's source: https://github.com/CircleCI-Public/kubernetes-orb
Created: February 26, 2019Version Published: July 22, 2022Releases: 24
Org Usage:
701

Orb Quick Start Guide

Use CircleCI version 2.1 at the top of your .circleci/config.yml file.

1 version: 2.1

Add the orbs stanza below your version, invoking the orb:

1 2 orbs: kubernetes: circleci/kubernetes@1.3.1

Use kubernetes elements in your existing workflows and jobs.

Usage Examples

delete

Delete kubernetes resource.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 version: '2.1' orbs: kubernetes: circleci/kubernetes@x.y.z jobs: delete: docker: - image: cimg/base:stable steps: - kubernetes/install-kubectl - kubernetes/delete-resource: now: true resource-names: nginx-deployment resource-types: deployments wait: true workflows: null

deployment

Deploying kubernetes resources.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 version: '2.1' orbs: kubernetes: circleci/kubernetes@x.y.z jobs: create-update: docker: - image: cimg/base:stable steps: - checkout - kubernetes/install-kubectl - kubernetes/create-or-update-resource: get-rollout-status: true resource-file-path: tests/nginx-deployment/deployment.yaml resource-name: deployment/nginx-deployment show-kubectl-command: true workflows: null

deployment-update

Update kubernetes resource.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 version: '2.1' orbs: kubernetes: circleci/kubernetes@x.y.z jobs: update: docker: - image: cimg/base:stable steps: - checkout - kubernetes/install-kubectl - kubernetes/update-container-image: container-image-updates: nginx=nginx:1.9.1 get-rollout-status: true resource-name: deployment/nginx-deployment workflows: null

install

Install kops and kubectl

1 2 3 4 5 6 7 8 9 10 11 version: '2.1' orbs: kubernetes: circleci/kubernetes@x.y.z jobs: build: macos: xcode: '13.2' steps: - checkout - kubernetes/install workflows: null

install-kops

Install kops

1 2 3 4 5 6 7 8 9 10 11 version: '2.1' orbs: kubernetes: circleci/kubernetes@x.y.z jobs: build: macos: xcode: '13.2' steps: - checkout - kubernetes/install-kops workflows: null

install-kubeconfig

Install kubeconfig

1 2 3 4 5 6 7 8 9 10 11 12 version: '2.1' orbs: kubernetes: circleci/kubernetes@1.0.0 jobs: build: macos: xcode: '13.2' steps: - checkout - kubernetes/install-kubeconfig: kubeconfig: KUBECONFIG_DATA workflows: null

install-kubectl

Install kubectl

1 2 3 4 5 6 7 8 9 10 11 version: '2.1' orbs: kubernetes: circleci/kubernetes@x.y.z jobs: build: macos: xcode: '13.2' steps: - checkout - kubernetes/install-kubectl workflows: null

Commands

create-or-update-resource

Create or update a kubernetes resource. Requirements: kubeconfig should be configured to connect to the cluster.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
action-type
Specify whether to use `kubectl create` or `kubectl apply` to create/update the resource.
No
apply
enum
dry-run
Whether the kubectl command will be executed in dry-run mode. Must be "none", "server", or "client"
No
''
enum
envsubst
Whether to run envsubst to substitute environment variables inside the deployment.yml finalizers.
No
false
boolean
get-rollout-status
Get the status of the rollout. This can only be used for resource types that are valid for usage with `kubectl rollout` subcommands.
No
false
boolean
kustomize
Enable it to run the kubectl command with the option -k for kustomize.
No
false
boolean
namespace
The kubernetes namespace that should be used.
No
''
string
pinned-revision-to-watch
Pin a specific revision to be watched and abort watching if it is rolled over by another revision. Only effective if get-rollout-status is set to true.
No
''
string
resource-file-path
Path to file used to create/update the resource.
Yes
-
string
resource-name
Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment This is required if get-rollout-status is set to true.
No
''
string
server-side-apply
Whether to run apply in the server instead of the client. Only effective if action-type is set to `apply`.
No
false
boolean
show-kubectl-command
Whether to show the kubectl command used.
No
false
boolean
watch-rollout-status
Whether to watch the status of the latest rollout until it's done. Only effective if get-rollout-status is set to true.
No
true
boolean
watch-timeout
The length of time to wait before ending the watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h). Only effective if get-rollout-status is set to true.
No
''
string

delete-resource

Delete kubernetes resource(s). Requirements: kubeconfig should be configured to connect to the cluster.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
all
If true, deletes all resources including uninitialized ones, in the namespace of the specified resource types.
No
false
boolean
cascade
If true, cascades the deletion of the resources managed by this resource. (e.g. Pods created by a ReplicationController) Must be "background" or "foreground"
No
background
enum
dry-run
Whether the kubectl command will be executed in dry-run mode. Must be "none", "server", or "client"
No
''
enum
force
Only used when "0" is specified for grace-period. If true, immediately remove resources from API and bypass graceful deletion. Note that immediate deletion of some resources may result in inconsistency or data loss and requires confirmation.
No
false
boolean
grace-period
Period of time in seconds given to the resource to terminate gracefully. A value of "-1" will be ignored.
No
-1
integer
ignore-not-found
If true, treats "resource not found" as a successful delete. (Note: unlike the kubectl command, this does not default to true when the "all" parameter value is set to true)
No
false
boolean
kustomize
Enable it to run the kubectl command with the option -k for kustomize.
No
false
boolean
label-selector
Use a label selector on the resource(s) to be deleted. Effective only when the resource-types parameter is specified. Cannot be used together with the resource-names parameter.
No
''
string
namespace
The kubernetes namespace that should be used.
No
''
string
now
If true, resources are signaled for immediate shutdown.
No
false
boolean
resource-file-path
Path to file used to describe the resource. Should not be set when the "resource-types" parameter is specified.
No
''
string
resource-names
Specifies the names of resource(s) to be deleted. Effective only when the resource-types parameter is specified. Cannot be used together with the label-selector parameter.
No
''
string
resource-types
Specify what is to be deleted in the form of resource types. This parameter is meant to be combined with either the "resource-names" or the "label-selector" parameter. e.g. use the value "pods,services" for "resource-types" and the value "name=myLabel" for "label-selector" to delete pods and services with the label name=myLabel. e.g. use the value "pods,services" for "resource-types" and the value "baz foo" for "resource-names" to delete pods and services the match the names "baz" and "foo". Should not be set when the "resource-file-path" parameter is specified.
No
''
string
show-kubectl-command
Whether to show the kubectl command used.
No
false
boolean
wait
If true, wait for resources to be gone before returning. This waits for finalizers.
No
true
boolean

get-rollout-status

Gets the rollout status of a resource. This command is only valid for resource types that are valid for usage with `kubectl rollout` subcommands. Requirements: kubeconfig should be configured to connect to the cluster.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
namespace
The kubernetes namespace that should be used.
No
''
string
pinned-revision-to-watch
Pin a specific revision to be watched and abort watching if it is rolled over by another revision.
No
''
string
resource-file-path
Path to file used to get the status of the resource.
No
''
string
resource-name
Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment
No
''
string
show-kubectl-command
Whether to show the kubectl command used.
No
false
boolean
watch-rollout-status
Whether to watch the status of the latest rollout until it's done.
No
true
boolean
watch-timeout
The length of time to wait before ending the watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h).
No
''
string

install

Installs kubectl and kops (latest releases, by default) Requirements: curl, amd64 architecture

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
kops-version
-
No
latest
string
kubectl-version
-
No
latest
string
max-time
This parameter will enable the curl command to not timeout for 600 seconds
No
false
boolean

install-kops

Installs kops (latest release, by default) Requirements: curl, amd64 architecture

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
kops-version
-
No
latest
string

install-kubeconfig

Install kubeconfig file with the contents taken from the value of an environment variable, which should be base64-encoded.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
kubeconfig
Environment variable name containing base64-encoded kubeconfig data
No
KUBECONFIG_DATA
env_var_name

install-kubectl

Installs kubectl (latest release, by default) Requirements: curl, amd64 architecture

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
kubectl-version
-
No
latest
string
max-time
This parameter will enable the curl command to not timeout for 600 seconds
No
false
boolean

rollback

Rollback a deployment or daemonset resource. Requirements: kubeconfig should be configured to connect to the cluster.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
get-rollout-status
Get the status of the rollout. This can only be used for resource types that are valid for usage with `kubectl rollout` subcommands.
No
false
boolean
namespace
The kubernetes namespace that should be used.
No
''
string
resource-name
Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment
Yes
-
string
show-kubectl-command
Whether to show the kubectl command used.
No
false
boolean
watch-rollout-status
Whether to watch the status of the latest rollout until it's done.
No
true
boolean
watch-timeout
The length of time to wait before ending the watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h).
No
''
string

update-container-image

Updates existing container image(s) of resources on the cluster using the `kubectl set image` command. Requirements: kubeconfig should be configured to connect to the cluster.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
container-image-updates
Specify a list of container image updates (space-delimited name value pairs in the form CONTAINER_NAME_1=CONTAINER_IMAGE_1 ... CONTAINER_NAME_N=CONTAINER_IMAGE_N) to be applied to the resource via `kubectl set image`. e.g. "busybox=busybox nginx=nginx:1.9.1"
Yes
-
string
dry-run
Whether the kubectl command will be executed in dry-run mode.
No
''
enum
get-rollout-status
Get the status of the rollout. This can only be used for resource types that are valid for usage with `kubectl rollout` subcommands.
No
false
boolean
namespace
The kubernetes namespace that should be used.
No
''
string
pinned-revision-to-watch
Pin a specific revision to be watched and abort watching if it is rolled over by another revision. Only effective if get-rollout-status is set to true.
No
''
string
resource-file-path
Path to file used to update the resource. Either resource-file-path or resource-name need to be specified.
No
''
string
resource-name
Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment Either resource-file-path or resource-name need to be specified. This is required if get-rollout-status is set to true.
No
''
string
show-kubectl-command
Whether to show the kubectl command used.
No
false
boolean
watch-rollout-status
Whether to watch the status of the latest rollout until it's done. Only effective if get-rollout-status is set to true.
No
true
boolean
watch-timeout
The length of time to wait before ending the watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h). Only effective if get-rollout-status is set to true.
No
''
string

Orb Source

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 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 # This code is licensed from CircleCI to the user under the MIT license. # See here for details: https://circleci.com/developer/orbs/licensing version: 2.1 description: | A collection of tools for working with Kubernetes on CircleCI View this orb's source: https://github.com/CircleCI-Public/kubernetes-orb display: home_url: https://kubernetes.io/ source_url: https://github.com/CircleCI-Public/kubernetes-orb commands: create-or-update-resource: description: | Create or update a kubernetes resource. Requirements: kubeconfig should be configured to connect to the cluster. parameters: action-type: default: apply description: | Specify whether to use `kubectl create` or `kubectl apply` to create/update the resource. enum: - create - apply type: enum dry-run: default: "" description: | Whether the kubectl command will be executed in dry-run mode. Must be "none", "server", or "client" enum: - "" - server - client type: enum envsubst: default: false description: | Whether to run envsubst to substitute environment variables inside the deployment.yml finalizers. type: boolean get-rollout-status: default: false description: | Get the status of the rollout. This can only be used for resource types that are valid for usage with `kubectl rollout` subcommands. type: boolean kustomize: default: false description: | Enable it to run the kubectl command with the option -k for kustomize. type: boolean namespace: default: "" description: | The kubernetes namespace that should be used. type: string pinned-revision-to-watch: default: "" description: | Pin a specific revision to be watched and abort watching if it is rolled over by another revision. Only effective if get-rollout-status is set to true. type: string resource-file-path: description: | Path to file used to create/update the resource. type: string resource-name: default: "" description: | Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment This is required if get-rollout-status is set to true. type: string server-side-apply: default: false description: | Whether to run apply in the server instead of the client. Only effective if action-type is set to `apply`. type: boolean show-kubectl-command: default: false description: | Whether to show the kubectl command used. type: boolean watch-rollout-status: default: true description: | Whether to watch the status of the latest rollout until it's done. Only effective if get-rollout-status is set to true. type: boolean watch-timeout: default: "" description: | The length of time to wait before ending the watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h). Only effective if get-rollout-status is set to true. type: string steps: - run: command: "#!/bin/bash\nRESOURCE_FILE_PATH=$(eval echo \"$PARAM_RESOURCE_FILE_PATH\")\nACTION_TYPE=$(eval echo \"$PARAM_ACTION_TYPE\")\nNAMESPACE=$(eval echo \"$PARAM_NAMESPACE\")\nDRY_RUN=$(eval echo \"$PARAM_DRY_RUN\")\nKUSTOMIZE=$(eval echo \"$PARAM_KUSTOMIZE\")\nSERVER_SIDE_APPLY=$(eval echo \"$PARAM_SERVER_SIDE_APPLY\")\nENVSUBST=$(eval echo \"$PARAM_ENVSUBST\")\n\n[ -w /usr/local/bin ] && SUDO=\"\" || SUDO=sudo\n\nif [ -n \"${ACTION_TYPE}\" ]; then\n set -- \"$@\" \"${ACTION_TYPE}\"\n\n if [ \"${ACTION_TYPE}\" == \"apply\" ] && [ \"$SERVER_SIDE_APPLY\" == \"1\" ]; then\n set -- \"$@\" --server-side\n fi\nfi\nif [ -n \"$RESOURCE_FILE_PATH\" ]; then\n if [ \"$ENVSUBST\" == \"1\" ]; then \n $SUDO apt-get update && $SUDO apt-get install -y gettext-base\n FILENAME=\"$(basename \"$RESOURCE_FILE_PATH\")\"\n envsubst < \"$RESOURCE_FILE_PATH\" > /tmp/\"$FILENAME\"; mv /tmp/\"$FILENAME\" \"$RESOURCE_FILE_PATH\"\n fi\n if [ \"$KUSTOMIZE\" == \"1\" ]; then\n set -- \"$@\" -k\n else\n set -- \"$@\" -f\n fi\n set -- \"$@\" \"$RESOURCE_FILE_PATH\"\nfi\nif [ -n \"${NAMESPACE}\" ]; then\n set -- \"$@\" --namespace=\"${NAMESPACE}\"\nfi\nif [ -n \"${DRY_RUN}\" ]; then\n set -- \"$@\" --dry-run=\"${DRY_RUN}\"\nfi\nif [ \"$SHOW_EKSCTL_COMMAND\" == \"1\" ]; then\n set -x\nfi\nkubectl \"$@\"\nif [ \"$SHOW_EKSCTL_COMMAND\" == \"1\" ]; then\n set +x\nfi\n" environment: PARAM_ACTION_TYPE: << parameters.action-type >> PARAM_DRY_RUN: << parameters.dry-run >> PARAM_ENVSUBST: << parameters.envsubst >> PARAM_KUSTOMIZE: << parameters.kustomize >> PARAM_NAMESPACE: << parameters.namespace >> PARAM_RESOURCE_FILE_PATH: << parameters.resource-file-path >> PARAM_SERVER_SIDE_APPLY: << parameters.server-side-apply >> name: Create/update the k8s resource - when: condition: << parameters.get-rollout-status >> steps: - get-rollout-status: namespace: << parameters.namespace >> pinned-revision-to-watch: << parameters.pinned-revision-to-watch >> resource-name: << parameters.resource-name >> watch-rollout-status: << parameters.watch-rollout-status >> watch-timeout: << parameters.watch-timeout >> delete-resource: description: | Delete kubernetes resource(s). Requirements: kubeconfig should be configured to connect to the cluster. parameters: all: default: false description: | If true, deletes all resources including uninitialized ones, in the namespace of the specified resource types. type: boolean cascade: default: background description: | If true, cascades the deletion of the resources managed by this resource. (e.g. Pods created by a ReplicationController) Must be "background" or "foreground" enum: - background - foreground type: enum dry-run: default: "" description: | Whether the kubectl command will be executed in dry-run mode. Must be "none", "server", or "client" enum: - "" - server - client type: enum force: default: false description: | Only used when "0" is specified for grace-period. If true, immediately remove resources from API and bypass graceful deletion. Note that immediate deletion of some resources may result in inconsistency or data loss and requires confirmation. type: boolean grace-period: default: -1 description: | Period of time in seconds given to the resource to terminate gracefully. A value of "-1" will be ignored. type: integer ignore-not-found: default: false description: | If true, treats "resource not found" as a successful delete. (Note: unlike the kubectl command, this does not default to true when the "all" parameter value is set to true) type: boolean kustomize: default: false description: | Enable it to run the kubectl command with the option -k for kustomize. type: boolean label-selector: default: "" description: | Use a label selector on the resource(s) to be deleted. Effective only when the resource-types parameter is specified. Cannot be used together with the resource-names parameter. type: string namespace: default: "" description: | The kubernetes namespace that should be used. type: string now: default: false description: | If true, resources are signaled for immediate shutdown. type: boolean resource-file-path: default: "" description: | Path to file used to describe the resource. Should not be set when the "resource-types" parameter is specified. type: string resource-names: default: "" description: | Specifies the names of resource(s) to be deleted. Effective only when the resource-types parameter is specified. Cannot be used together with the label-selector parameter. type: string resource-types: default: "" description: | Specify what is to be deleted in the form of resource types. This parameter is meant to be combined with either the "resource-names" or the "label-selector" parameter. e.g. use the value "pods,services" for "resource-types" and the value "name=myLabel" for "label-selector" to delete pods and services with the label name=myLabel. e.g. use the value "pods,services" for "resource-types" and the value "baz foo" for "resource-names" to delete pods and services the match the names "baz" and "foo". Should not be set when the "resource-file-path" parameter is specified. type: string show-kubectl-command: default: false description: | Whether to show the kubectl command used. type: boolean wait: default: true description: | If true, wait for resources to be gone before returning. This waits for finalizers. type: boolean steps: - run: command: | #!/bin/bash RESOURCE_FILE_PATH=$(eval echo "$PARAM_RESOURCE_FILE_PATH") RESOURCE_TYPES=$(eval echo "$PARAM_RESOURCE_TYPES") RESOURCE_NAMES=$(eval echo "$PARAM_RESOURCE_NAMES") LABEL_SELECTOR=$(eval echo "$PARAM_LABEL_SELECTOR") ALL=$(eval echo "$PARAM_ALL") CASCADE=$(eval echo "$PARAM_CASCADE") FORCE=$(eval echo "$PARAM_FORCE") GRACE_PERIOD=$(eval echo "$PARAM_GRACE_PERIOD") IGNORE_NOT_FOUND=$(eval echo "$PARAM_IGNORE_NOT_FOUND") NOW=$(eval echo "$PARAM_NOW") WAIT=$(eval echo "$PARAM_WAIT") NAMESPACE=$(eval echo "$PARAM_NAMESPACE") DRY_RUN=$(eval echo "$PARAM_DRY_RUN") KUSTOMIZE=$(eval echo "$PARAM_KUSTOMIZE") if [ -n "${RESOURCE_FILE_PATH}" ]; then if [ "${KUSTOMIZE}" == "1" ]; then set -- "$@" -k else set -- "$@" -f fi set -- "$@" "${RESOURCE_FILE_PATH}" elif [ -n "${RESOURCE_TYPES}" ]; then set -- "$@" "${RESOURCE_TYPES}" if [ -n "${RESOURCE_NAMES}" ]; then set -- "$@" "${RESOURCE_NAMES}" elif [ -n "${LABEL_SELECTOR}" ]; then set -- "$@" -l set -- "$@" "${LABEL_SELECTOR}" fi fi if [ "${ALL}" == "true" ]; then set -- "$@" --all=true fi if [ "${FORCE}" == "true" ]; then set -- "$@" --force=true fi if [ "${GRACE_PERIOD}" != "-1" ]; then set -- "$@" --grace-period="${GRACE_PERIOD}" fi if [ "${IGNORE_NOT_FOUND}" == "true" ]; then set -- "$@" --ignore-not-found=true fi if [ "${NOW}" == "true" ]; then set -- "$@" --now=true fi if [ -n "${NAMESPACE}" ]; then set -- "$@" --namespace="${NAMESPACE}" fi if [ -n "${DRY_RUN}" ]; then set -- "$@" --dry-run="${DRY_RUN}" fi set -- "$@" --wait="${WAIT}" set -- "$@" --cascade="${CASCADE}" if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set -x fi kubectl delete "$@" if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set +x fi environment: PARAM_ALL: << parameters.all >> PARAM_CASCADE: << parameters.cascade >> PARAM_DRY_RUN: << parameters.dry-run >> PARAM_FORCE: << parameters.force >> PARAM_GRACE_PERIOD: << parameters.grace-period >> PARAM_IGNORE_NOT_FOUND: << parameters.ignore-not-found >> PARAM_KUSTOMIZE: << parameters.kustomize >> PARAM_LABEL_SELECTOR: << parameters.label-selector >> PARAM_NAMESPACE: << parameters.namespace >> PARAM_NOW: << parameters.now >> PARAM_RESOURCE_FILE_PATH: << parameters.resource-file-path >> PARAM_RESOURCE_NAMES: << parameters.resource-names >> PARAM_RESOURCE_TYPES: << parameters.resource-types >> PARAM_WAIT: << parameters.wait >> name: Delete the k8s resource(s) get-rollout-status: description: | Gets the rollout status of a resource. This command is only valid for resource types that are valid for usage with `kubectl rollout` subcommands. Requirements: kubeconfig should be configured to connect to the cluster. parameters: namespace: default: "" description: | The kubernetes namespace that should be used. type: string pinned-revision-to-watch: default: "" description: | Pin a specific revision to be watched and abort watching if it is rolled over by another revision. type: string resource-file-path: default: "" description: | Path to file used to get the status of the resource. type: string resource-name: default: "" description: | Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment type: string show-kubectl-command: default: false description: | Whether to show the kubectl command used. type: boolean watch-rollout-status: default: true description: | Whether to watch the status of the latest rollout until it's done. type: boolean watch-timeout: default: "" description: | The length of time to wait before ending the watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h). type: string steps: - run: command: | #!/bin/bash RESOURCE_NAME=$(eval echo "$PARAM_RESOURCE_NAME") NAMESPACE=$(eval echo "$PARAM_NAMESPACE") WATCH_ROLLOUT_STATUS=$(eval echo "$PARAM_WATCH_ROLLOUT_STATUS") PINNED_REVISION_TO_WATCH=$(eval echo "$PARAM_PINNED_REVISION_TO_WATCH") WATCH_TIMEOUT=$(eval echo "$PARAM_WATCH_TIMEOUT") RESOURCE_FILE_PATH=$(eval echo "$PARAM_RESOURCE_FILE_PATH") if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set +x fi if [ -n "${RESOURCE_NAME}" ]; then set -- "$@" "${RESOURCE_NAME}" fi if [ -n "${NAMESPACE}" ]; then set -- "$@" "--namespace=${NAMESPACE}" fi if [ "${WATCH_ROLLOUT_STATUS}" == "true" ]; then set -- "$@" --watch=true if [ -n "${PINNED_REVISION_TO_WATCH}" ]; then set -- "$@" "--revision=${PINNED_REVISION_TO_WATCH}" fi if [ -n "${WATCH_TIMEOUT}" ]; then set -- "$@" "--timeout=${WATCH_TIMEOUT}" fi fi if [ -n "$RESOURCE_FILE_PATH" ]; then kubectl rollout status -f "$RESOURCE_FILE_PATH" "$@" else kubectl rollout status "$@" fi environment: PARAM_NAMESPACE: << parameters.namespace >> PARAM_PINNED_REVISION_TO_WATCH: << parameters.pinned-revision-to-watch >> PARAM_RESOURCE_FILE_PATH: << parameters.resource-file-path >> PARAM_RESOURCE_NAME: << parameters.resource-name >> PARAM_WATCH_ROLLOUT_STATUS: << parameters.watch-rollout-status >> PARAM_WATCH_TIMEOUT: << parameters.watch-timeout >> name: Show the resource rollout status - run: command: |+ #!/bin/bash RESOURCE_NAME=$(eval echo "$PARAM_RESOURCE_NAME") NAMESPACE=$(eval echo "$PARAM_NAMESPACE") RESOURCE_FILE_PATH=$(eval echo "$PARAM_RESOURCE_FILE_PATH") if [ -n "${RESOURCE_FILE_PATH}" ]; then if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set -x fi kubectl describe -f "${RESOURCE_FILE_PATH}" if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set +x fi else if [ -n "${NAMESPACE}" ]; then set -- "$@" "--namespace=${NAMESPACE}" fi if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set -x fi kubectl describe "${RESOURCE_NAME}" "$@" if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set +x fi fi environment: PARAM_NAMESPACE: << parameters.namespace >> PARAM_RESOURCE_FILE_PATH: << parameters.resource-file-path >> PARAM_RESOURCE_NAME: << parameters.resource-name >> name: Get a description of the resource install: description: | Installs kubectl and kops (latest releases, by default) Requirements: curl, amd64 architecture parameters: kops-version: default: latest type: string kubectl-version: default: latest type: string max-time: default: false description: | This parameter will enable the curl command to not timeout for 600 seconds type: boolean steps: - install-kops: kops-version: << parameters.kops-version >> - install-kubectl: kubectl-version: << parameters.kubectl-version >> max-time: << parameters.max-time >> install-kops: description: | Installs kops (latest release, by default) Requirements: curl, amd64 architecture parameters: kops-version: default: latest type: string steps: - run: command: | #!/bin/bash KOPS_VERSION=$(eval echo "$PARAM_KOPS_VERSION") if [[ "$KOPS_VERSION" == "latest" ]]; then # get latest kops release KOPS_VERSION=$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4) fi PLATFORM="linux" if [ -n "$(uname | grep "Darwin")" ]; then PLATFORM="darwin" fi # download kops curl -Lo kops https://github.com/kubernetes/kops/releases/download/$KOPS_VERSION/kops-$PLATFORM-amd64 [ -w /usr/local/bin ] && SUDO="" || SUDO=sudo $SUDO chmod +x kops $SUDO mv kops /usr/local/bin/kops environment: PARAM_KOPS_VERSION: <<parameters.kops-version>> name: Install kops install-kubeconfig: description: | Install kubeconfig file with the contents taken from the value of an environment variable, which should be base64-encoded. parameters: kubeconfig: default: KUBECONFIG_DATA description: Environment variable name containing base64-encoded kubeconfig data type: env_var_name steps: - run: command: | if [ -n "${<<parameters.kubeconfig>>}" ]; then mkdir -p $HOME/.kube echo -n "${<<parameters.kubeconfig>>}" | base64 --decode > $HOME/.kube/config fi name: Install kubeconfig install-kubectl: description: | Installs kubectl (latest release, by default) Requirements: curl, amd64 architecture parameters: kubectl-version: default: latest type: string max-time: default: false description: | This parameter will enable the curl command to not timeout for 600 seconds type: boolean steps: - run: command: "#!/bin/bash\nKUBECTL_VERSION=$(eval echo \"$PARAM_KUBECTL_VERSION\")\nMAX_TIME=$(eval echo \"$PARAM_MAX_TIME\")\nif [ \"$KUBECTL_VERSION\" == \"latest\" ]; then\n # get latest kubectl release\n KUBECTL_VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)\nfi\n\nPLATFORM=\"linux\"\nif [ -n \"$(uname | grep \"Darwin\")\" ]; then\n PLATFORM=\"darwin\"\nfi\n\n# download kubectl\nif [ \"$MAX_TIME\" == \"1\" ]; then\n curl --max-time 300 -LO https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/$PLATFORM/amd64/kubectl\nelse \n curl -LO https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/$PLATFORM/amd64/kubectl\nfi\n\n[ -w /usr/local/bin ] && SUDO=\"\" || SUDO=sudo\n\n$SUDO chmod +x ./kubectl\n\n$SUDO mv ./kubectl /usr/local/bin\n" environment: PARAM_KUBECTL_VERSION: <<parameters.kubectl-version>> PARAM_MAX_TIME: <<parameters.max-time>> name: Install kubectl rollback: description: | Rollback a deployment or daemonset resource. Requirements: kubeconfig should be configured to connect to the cluster. parameters: get-rollout-status: default: false description: | Get the status of the rollout. This can only be used for resource types that are valid for usage with `kubectl rollout` subcommands. type: boolean namespace: default: "" description: | The kubernetes namespace that should be used. type: string resource-name: description: | Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment type: string show-kubectl-command: default: false description: | Whether to show the kubectl command used. type: boolean watch-rollout-status: default: true description: | Whether to watch the status of the latest rollout until it's done. type: boolean watch-timeout: default: "" description: | The length of time to wait before ending the watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h). type: string steps: - run: command: | #!/bin/bash RESOURCE_NAME=$(eval echo "$PARAM_RESOURCE_NAME") NAMESPACE=$(eval echo "$PARAM_NAMESPACE") if [ -n "${RESOURCE_NAME}" ]; then set -- "$@" "${RESOURCE_NAME}" fi if [ -n "${NAMESPACE}" ]; then set -- "$@" "--namespace=${NAMESPACE}" fi if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set -x fi kubectl rollout undo "$@" if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set +x fi environment: PARAM_NAMESPACE: << parameters.namespace >> PARAM_RESOURCE_NAME: << parameters.resource-name >> name: Rollback the resource - when: condition: << parameters.get-rollout-status >> steps: - get-rollout-status: namespace: << parameters.namespace >> resource-name: << parameters.resource-name >> watch-rollout-status: << parameters.watch-rollout-status >> watch-timeout: << parameters.watch-timeout >> update-container-image: description: | Updates existing container image(s) of resources on the cluster using the `kubectl set image` command. Requirements: kubeconfig should be configured to connect to the cluster. parameters: container-image-updates: description: | Specify a list of container image updates (space-delimited name value pairs in the form CONTAINER_NAME_1=CONTAINER_IMAGE_1 ... CONTAINER_NAME_N=CONTAINER_IMAGE_N) to be applied to the resource via `kubectl set image`. e.g. "busybox=busybox nginx=nginx:1.9.1" type: string dry-run: default: "" description: | Whether the kubectl command will be executed in dry-run mode. enum: - "" - server - client type: enum get-rollout-status: default: false description: | Get the status of the rollout. This can only be used for resource types that are valid for usage with `kubectl rollout` subcommands. type: boolean namespace: default: "" description: | The kubernetes namespace that should be used. type: string pinned-revision-to-watch: default: "" description: | Pin a specific revision to be watched and abort watching if it is rolled over by another revision. Only effective if get-rollout-status is set to true. type: string resource-file-path: default: "" description: | Path to file used to update the resource. Either resource-file-path or resource-name need to be specified. type: string resource-name: default: "" description: | Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment Either resource-file-path or resource-name need to be specified. This is required if get-rollout-status is set to true. type: string show-kubectl-command: default: false description: | Whether to show the kubectl command used. type: boolean watch-rollout-status: default: true description: | Whether to watch the status of the latest rollout until it's done. Only effective if get-rollout-status is set to true. type: boolean watch-timeout: default: "" description: | The length of time to wait before ending the watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h). Only effective if get-rollout-status is set to true. type: string steps: - run: command: | #!/bin/bash RESOURCE_FILE_PATH=$(eval echo "$PARAM_RESOURCE_FILE_PATH") RESOURCE_NAME=$(eval echo "$PARAM_RESOURCE_NAME") CONTAINER_IMAGE_UPDATES=$(eval echo "$PARAM_CONTAINER_IMAGE_UPDATES") NAMESPACE=$(eval echo "$PARAM_NAMESPACE") DRY_RUN=$(eval echo "$PARAM_DRY_RUN") if [ -n "${RESOURCE_FILE_PATH}" ]; then set -- "$@" -f set -- "$@" "${RESOURCE_FILE_PATH}" elif [ -n "${RESOURCE_NAME}" ]; then set -- "$@" "${RESOURCE_NAME}" else echo "Error: The update-container-image command requires either resource-file-path or resource-name to be specified." exit 1 fi if [ -n "${CONTAINER_IMAGE_UPDATES}" ]; then set -- "$@" ${CONTAINER_IMAGE_UPDATES} fi if [ -n "${NAMESPACE}" ]; then set -- "$@" --namespace="${NAMESPACE}" fi if [ -n "${DRY_RUN}" ]; then set -- "$@" --dry-run "${DRY_RUN}" fi if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set -x fi kubectl set image "$@" if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then set +x fi environment: PARAM_CONTAINER_IMAGE_UPDATES: << parameters.container-image-updates >> PARAM_NAMESPACE: << parameters.namespace >> PARAM_RESOURCE_FILE_PATH: << parameters.resource-file-path >> PARAM_RESOURCE_NAME: << parameters.resource-name >> name: Update the container image(s) for the resource - when: condition: << parameters.get-rollout-status >> steps: - get-rollout-status: namespace: << parameters.namespace >> pinned-revision-to-watch: << parameters.pinned-revision-to-watch >> resource-name: << parameters.resource-name >> watch-rollout-status: << parameters.watch-rollout-status >> watch-timeout: << parameters.watch-timeout >> examples: delete: description: | Delete kubernetes resource. usage: version: "2.1" orbs: kubernetes: circleci/kubernetes@x.y.z jobs: delete: docker: - image: cimg/base:stable steps: - kubernetes/install-kubectl - kubernetes/delete-resource: now: true resource-names: nginx-deployment resource-types: deployments wait: true workflows: null deployment: description: | Deploying kubernetes resources. usage: version: "2.1" orbs: kubernetes: circleci/kubernetes@x.y.z jobs: create-update: docker: - image: cimg/base:stable steps: - checkout - kubernetes/install-kubectl - kubernetes/create-or-update-resource: get-rollout-status: true resource-file-path: tests/nginx-deployment/deployment.yaml resource-name: deployment/nginx-deployment show-kubectl-command: true workflows: null deployment-update: description: | Update kubernetes resource. usage: version: "2.1" orbs: kubernetes: circleci/kubernetes@x.y.z jobs: update: docker: - image: cimg/base:stable steps: - checkout - kubernetes/install-kubectl - kubernetes/update-container-image: container-image-updates: nginx=nginx:1.9.1 get-rollout-status: true resource-name: deployment/nginx-deployment workflows: null install: description: | Install kops and kubectl usage: version: "2.1" orbs: kubernetes: circleci/kubernetes@x.y.z jobs: build: macos: xcode: "13.2" steps: - checkout - kubernetes/install workflows: null install-kops: description: | Install kops usage: version: "2.1" orbs: kubernetes: circleci/kubernetes@x.y.z jobs: build: macos: xcode: "13.2" steps: - checkout - kubernetes/install-kops workflows: null install-kubeconfig: description: | Install kubeconfig usage: version: "2.1" orbs: kubernetes: circleci/kubernetes@1.0.0 jobs: build: macos: xcode: "13.2" steps: - checkout - kubernetes/install-kubeconfig: kubeconfig: KUBECONFIG_DATA workflows: null install-kubectl: description: | Install kubectl usage: version: "2.1" orbs: kubernetes: circleci/kubernetes@x.y.z jobs: build: macos: xcode: "13.2" steps: - checkout - kubernetes/install-kubectl workflows: null
Developer Updates
Get tips to optimize your builds
Or join our research panel and give feedback
By submitting this form, you are agreeing to ourTerms of UseandPrivacy Policy.