A Replication Controller ensures that a specified number of pod “replicas” are running at any one time. In other words, a Replication Controller makes sure that a pod or homogeneous set of pods are always up and available. If there are too many pods, it will kill some. If there are too few, the Replication Controller will start more.
resource "kubernetes_replication_controller_v1" "example" {
metadata {
name = "terraform-example"
labels = {
test = "MyExampleApp"
}
}
spec {
selector = {
test = "MyExampleApp"
}
template {
metadata {
labels = {
test = "MyExampleApp"
}
annotations = {
"key1" = "value1"
}
}
spec {
container {
image = "nginx:1.21.6"
name = "example"
liveness_probe {
http_get {
path = "/"
port = 80
http_header {
name = "X-Custom-Header"
value = "Awesome"
}
}
initial_delay_seconds = 3
period_seconds = 3
}
resources {
limits = {
cpu = "0.5"
memory = "512Mi"
}
requests = {
cpu = "250m"
memory = "50Mi"
}
}
}
}
}
}
}
The following arguments are supported:
metadata
- (Required) Standard replication controller's metadata. For more info see Kubernetes referencespec
- (Required) Spec defines the specification of the desired behavior of the replication controller. For more info see Kubernetes referencemetadata
annotations
- (Optional) An unstructured key value map stored with the replication controller that may be used to store arbitrary metadata.generate_name
- (Optional) Prefix, used by the server, to generate a unique name ONLY IF the name
field has not been provided. This value will also be combined with a unique suffix. For more info see Kubernetes referencelabels
- (Optional) Map of string keys and values that can be used to organize and categorize (scope and select) the replication controller.name
- (Optional) Name of the replication controller, must be unique. Cannot be updated. For more info see Kubernetes referencenamespace
- (Optional) Namespace defines the space within which name of the replication controller must be unique.generation
- A sequence number representing a specific generation of the desired state.resource_version
- An opaque value that represents the internal version of this replication controller that can be used by clients to determine when replication controller has changed. For more info see Kubernetes referenceuid
- The unique in time and space value for this replication controller. For more info see Kubernetes referencespec
min_ready_seconds
- (Optional) Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)replicas
- (Optional) The number of desired replicas. Defaults to 1. For more info see Kubernetes referenceselector
- (Required) A label query over pods that should match the Replicas count. Label keys and values that must match in order to be controlled by this replication controller. Should match labels (metadata.0.labels
). For more info see Kubernetes referencetemplate
- (Required) Template is the object that describes the pod that will be created if insufficient replicas are detected. This takes precedence over a TemplateRef. For more info see Kubernetes referencespec.template
metadata
- (Optional) Standard object's metadata. For more info see Kubernetes reference. While required by the kubernetes API, this field is marked as optional to allow the usage of the deprecated pod spec fields that were mistakenly placed directly under the template
block.
spec
- (Optional) Specification of the desired behavior of the pod. For more info see Kubernetes reference
spec.template.metadata
annotations
- (Optional) An unstructured key value map stored with the replication controller that may be used to store arbitrary metadata. For more info see Kubernetes referencegenerate_name
- (Optional) Prefix, used by the server, to generate a unique name ONLY IF the name
field has not been provided. This value will also be combined with a unique suffix. For more info see Kubernetes referencelabels
- (Optional) Map of string keys and values that can be used to organize and categorize (scope and select) the pods managed by this replication controller . Should match selector
. For more info see Kubernetes referencename
- (Optional) Name of the replication controller, must be unique. Cannot be updated. For more info see Kubernetes referencenamespace
- (Optional) Namespace defines the space within which name of the replication controller must be unique.spec.template.spec
These arguments are the same as the for the spec
block of a Pod.
Please see the Pod resource for reference.
The following Timeout configuration options are available:
create
- (Default 10 minutes
) Used for creating new controllerupdate
- (Default 10 minutes
) Used for updating a controllerdelete
- (Default 10 minutes
) Used for destroying a controllerReplication Controller can be imported using the namespace and name, e.g.
$ terraform import kubernetes_replication_controller_v1.example default/terraform-example