Spacelift
PrivacyT&Cs
  • 👋Hello, Spacelift!
  • 🚀Getting Started
  • 🌠Main concepts
    • Stack
      • Creating a stack
      • Stack settings
      • Organizing stacks
      • Stack locking
      • Drift detection
    • Configuration
      • Environment
      • Context
      • Runtime configuration
        • YAML reference
    • Run
      • Task
      • Proposed run (preview)
      • Tracked run (deployment)
      • Module test case
      • User-Provided Metadata
      • Run Promotion
      • Pull Request Comments
    • Policy
      • Login policy
      • Access policy
      • Approval policy
      • Initialization policy
      • Plan policy
      • Push policy
      • Task policy
      • Trigger policy
    • Resources
    • Worker pools
    • VCS Agent Pools
  • 🛰️Platforms
    • Terraform
      • Module registry
      • External modules
      • Provider
      • State management
      • Terragrunt
      • Version management
      • Handling .tfvars
      • CLI Configuration
      • Cost Estimation
      • Resource Sanitization
      • Storing Complex Variables
      • Debugging Guide
    • Pulumi
      • Getting started
        • C#
        • Go
        • JavaScript
        • Python
      • State management
      • Version management
    • CloudFormation
      • Getting Started
      • Reference
      • Integrating with SAM
      • Integrating with the serverless framework
    • Kubernetes
      • Getting Started
      • Authenticating
      • Custom Resources
      • Helm
      • Kustomize
  • ⚙️Integrations
    • Audit trail
    • Cloud Integrations
      • Amazon Web Services (AWS)
      • Microsoft Azure
      • Google Cloud Platform (GCP)
    • Source Control
      • GitHub
      • GitLab
      • Azure DevOps
      • Bitbucket Cloud
      • Bitbucket Datacenter/Server
    • Docker
    • GraphQL API
    • Single sign-on
      • GitLab OIDC Setup Guide
      • Okta OIDC Setup Guide
      • OneLogin OIDC Setup Guide
      • Azure AD OIDC Setup Guide
      • AWS IAM Identity SAML 2.0 Setup Guide
    • Slack
    • Webhooks
  • 📖Product
    • Privacy
    • Security
    • Support
      • Statement of Support
    • Disaster Continuity
    • Billing
      • Stripe
      • AWS Marketplace
    • Terms and conditions
    • Refund Policy
  • Cookie Policy
Powered by GitBook
On this page
  • Repository Creation
  • Create a new Stack
  • Integrate VCS
  • Configure Backend
  • Define Behavior
  • Name the Stack
  • Configure Integrations
  • Trigger a Run
  • Triggered Run Status
  • Default Removal of Deployments

Was this helpful?

  1. Platforms
  2. Kubernetes

Getting Started

Creating your first Kubernetes Stack with Spacelift, step by step.

Repository Creation

Start by creating a new deployment repository and name the file as deployment.yaml with the following code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Looking at the code, you will find that it deploys a single instance of Nginx.

Create a new Stack

In Spacelift, go ahead and click the Add Stack button to create a Stack in Spacelift.

Integrate VCS

Select the repository you created in the initial step, as seen in the picture.

Configure Backend

Choose Kubernetes from the dropdown list and type out the namespace.

Spacelift does not recommend leaving the Namespace blank due to the elevated level of access privilege required.

Define Behavior

Select the arrow next to Show Advanced Options to expose the advanced configuration options. To ensure the success of a Kubernetes deployment, the following options should be reviewed and validated.

  • Runner Image: By Default, Spacelift will add the necessary binary to run kubectl if not found. Including runner images not provided by Spacelift.

  • Customize workflow: During the initialization phase, you must specify the necessary command to ensure kubeconfig is updated and authenticated to the Kubernetes Cluster you will be authenticating against.

Spacelift can authenticate against any Kubernetes cluster, including local or cloud provider managed instances.

In the example above, I am authenticating to an AWS EKS Cluster and used the following command to update the kubeconfig for the necessary cluster. aws eks update-kubeconfig --region $region-name --name $cluster-name

Update the previous variables according to your deployment.

  • $region-name: AWS region where your Kubernetes cluster resides

  • $cluster-name: Name of your Kubernetes clusters

The above allows the worker to authenticate to the proper cluster before running the specified Kubernetes deployment in the repository that we created earlier.

Authentication with a Cloud Provider is required. After you Name the Stack, follow the Cloud Integrations section to ensure Spacelift can authenticate to your Kubernetes Cluster.

Name the Stack

Provide the name of your Stack. Labels and Description are not required but recommended.

Saving the Stack will redirect you to its Tracked Runs (Deployment) page.

Configure Integrations

To authenticate against a Kubernetes cluster provided by Cloud Provider managed service, Spacelift requires integration with the associated Cloud Provider.

Navigate to the Settings, Integrations page and select the dropdown arrow to access the following selection screen:

Necessary permissions to the Kubernetes Cluster are required.

The following links will help you set up the necessary integration with your Cloud Provider of choice.

Once you have configured the necessary integration, navigate the Stack landing page and Trigger a Run.

Trigger a Run

To Trigger a Run, select Trigger on the right side of the Stacks view.

Spacelift Label To help identify resources deployed to your Kubernetes cluster, Spacelift will add the following label to all resources. spacelift-stack=<stack-slug>

Triggered Run Status

Please review the documentation for a detailed view of each Run Phase and Status associated with Kubernetes.

Unconfirmed

After you manually trigger the Run in the Stack view, Spacelift will deploy a runner image, initialize the Cloud Provider, Authenticate with the Kubernetes Cluster and run the Deployment specified in the repository. After a successful planning phase, you can check the log to see the planned changes.

Planning Phase

Spacelift utilizes the dry run functionality of kubectl apply tocompare your code to the current state of the cluster and output the list of changes to be made. A slightly different dry run mode depending on the scenario:

  • --dry-run=server:Utilized when resources are available

  • --dry-run=client:Utilized when no resources are available

To confirm the Triggered run, click the CONFIRM button.

Finished Deployment

The following screen highlights the Finished Run and output from a successful deployment to your Kubernetes cluster.

Applying

Default Removal of Deployments

By default; if a YAML file is removed from your repository, the resources with an attached spacelift-stack=<stack-slug>label will be removed from the Kubernetes cluster.

The --prune flag will be utilized.

PreviousKubernetesNextAuthenticating

Last updated 2 years ago

Was this helpful?

You can learn more about this example deployment by navigating to the website from the official Kubernetes documentation.

The default timeout is set to 10 minutes. If a Kubernetes Deployment is expected to take longer, you can customize that using the KUBECTL_ROLLOUT_TIMEOUT environment variable. Review the to find out more about Spacelift environment variables..

🛰️
Run a Stateless Application Using a Deployment
AWS
Azure
GCP
documentation
Configuring the VCS settings.