Terraform Kubernetes Provider
repository·main·Indexed 23 days ago
https://github.com/hashicorp/terraform-provider-kubernetesA HashiCorp-maintained plugin that allows users to manage the full lifecycle of Kubernetes resources using Terraform configuration. The provider supports various environments including AKS, EKS, and GKE, and includes capabilities for OIDC authentication, cross-cluster management, and CertificateSigningRequest handling.
What's inside terraform-provider-kubernetes
- The Amazon Elastic Block Store (EBS) Container Storage Interface (CSI) Driver provides a CSI interface that allows Container Orchestrators (such as Kubernetes) to manage the lifecycle of Amazon EBS volumes. This driver is used to automate the provisioning, attaching, and managing of EBS volumes for containerized workloads.
Overview of the Kubernetes Provider for Terraform
mainThe Kubernetes provider for Terraform is a plugin that enables full lifecycle management of Kubernetes resources. It allows you to manage Kubernetes objects (such as Pods, Services, Deployments, etc.) using Terraform configuration files, integrating Kubernetes resource management into your existing Infrastructure as Code (IaC) workflows.Manage Kubernetes Ingress resources with kubernetes_ingress_v1
mainThekubernetes_ingress_v1resource allows you to manage Kubernetes Ingress objects. Ingress provides a collection of rules that enable inbound connections to reach backend endpoints. It is used to configure externally-reachable URLs for services, load balance traffic, terminate SSL, and provide name-based virtual hosting.Manage Kubernetes CronJobs with kubernetes_cron_job
mainThe
kubernetes_cron_jobresource allows you to create and manage Kubernetes CronJobs, which execute Jobs on a time-based schedule. Each CronJob object functions similarly to a line in a crontab file, running a job periodically based on a schedule written in Cron format.Important Considerations:
- Timezone: All
scheduletimes are based on the timezone of the Kubernetes master node where the job is initiated. - API Version Migration: For Kubernetes v1.25 and later, the
batch/v1beta1API has been removed. You should migrate to thebatch/v1API as per the Kubernetes migration guides.
- Timezone: All
Configure a validating admission webhook with kubernetes_validating_webhook_configuration_v1
mainThekubernetes_validating_webhook_configuration_v1resource is used to configure a validating admission webhook in Kubernetes. Validating admission webhooks are used to intercept requests to the Kubernetes API server and validate the objects being created or modified based on custom logic.Manage Horizontal Pod Autoscalers with kubernetes_horizontal_pod_autoscaler_v1
mainThe
kubernetes_horizontal_pod_autoscaler_v1resource automatically scales the number of pods in a replication controller, deployment, or replica set based on observed CPU utilization.To use this resource, you must define a
metadatablock for identification and aspecblock to define the scaling behavior and the target resource being scaled.resource "kubernetes_horizontal_pod_autoscaler_v1" "example" { metadata { name = "terraform-example" } spec { max_replicas = 10 min_replicas = 8 scale_target_ref { kind = "Deployment" name = "MyApp" } } }Manage Kubernetes Persistent Volumes with kubernetes_persistent_volume
mainThekubernetes_persistent_volumeresource allows you to provision and manage a piece of networked storage within a Kubernetes cluster. A Persistent Volume (PV) is a cluster-level resource with a lifecycle that is independent of any individual Pod that consumes it. This resource is part of thecore/v1API group.Configure a validating admission webhook with kubernetes_validating_webhook_configuration
mainThekubernetes_validating_webhook_configurationresource is used to configure a validating admission webhook in Kubernetes. Validating admission webhooks are used to intercept requests to the Kubernetes API server and validate the objects being created or modified based on custom logic.Manage Kubernetes IngressClass resources
mainThe
kubernetes_ingress_classresource allows you to define anIngressClassin Kubernetes. Ingresses use these classes to reference a specific controller and its configuration. This allows multiple controllers to coexist in a cluster, where each Ingress specifies which class it should use to be implemented.resource "kubernetes_ingress_class" "example" { metadata { name = "example" } spec { controller = "example.com/ingress-controller" parameters { api_group = "k8s.example.com" kind = "IngressParameters" name = "external-lb" } } }Manage Kubernetes Jobs with kubernetes_job_v1
mainThekubernetes_job_v1resource allows you to create and manage Kubernetes Jobs. A Job ensures that one or more Pods successfully terminate. It tracks successful completions and will restart a Pod if it fails or is deleted (e.g., due to node failure). You can use Jobs to run a single task to completion or to run multiple Pods in parallel. Deleting the Job resource in Terraform will clean up the Pods it created.Configure a mutating admission webhook with kubernetes_mutating_webhook_configuration_v1
mainThekubernetes_mutating_webhook_configuration_v1resource is used to configure a mutating admission webhook in Kubernetes. Mutating admission webhooks allow you to intercept requests to the Kubernetes API server and modify the objects being created or updated before they are persisted.Manage Horizontal Pod Autoscaler v2 with kubernetes_horizontal_pod_autoscaler_v2
mainThekubernetes_horizontal_pod_autoscaler_v2resource allows you to automatically scale the number of pods in a replication controller, deployment, or replica set. Scaling is typically driven by observed metrics such as CPU utilization or other custom metrics defined in thespec.