Reputation: 625
How can i create a nginx ingress
in azure kubernetes
using terraform
, earlier in this link , i remember seeing some steps as a mandatory installation for all setups, right now it seems to be removed and there is a specific way of installing for aks
in this link, should i rewrite all these to adapt to terraform
or is there any other smart way of installing nginx ingress
for aks
through terraform
Upvotes: 6
Views: 16784
Reputation: 41
I think adding http_application_routing_enabled
with true
should create nginx ingress for your cluster.
Upvotes: 0
Reputation: 549
You could try using Terraform's helm provider.
provider "helm" {
kubernetes {
host = azurerm_kubernetes_cluster.your_cluster.kube_config.0.host
client_key = base64decode(azurerm_kubernetes_cluster.your_cluster.kube_config.0.client_key)
client_certificate = base64decode(azurerm_kubernetes_cluster.your_cluster.kube_config.0.client_certificate)
cluster_ca_certificate = base64decode(azurerm_kubernetes_cluster.your_cluster.kube_config.0.cluster_ca_certificate)
}
}
data "helm_repository" "stable" {
name = "stable"
url = "https://kubernetes-charts.storage.googleapis.com"
}
resource "helm_release" "nginix_ingress" {
name = "nginx_ingress"
repository = data.helm_repository.stable.metadata.0.name
chart = "stable/nginx-ingress"
namespace = "kube-system"
}
If your cluster is already created, you will have to import it as well using a data source. helm_release
also supports custom values. Here is the link if you need more information.
Upvotes: 9
Reputation: 1404
I offer an alternative, in my opinion better, way to provision Kubernetes services like Nginx ingress using Terraform.
My kustomize based modules have two main benefits over using helm based modules:
terraform plan
If you're interested, here's a detailed comparison between my kustomize based Nginx ingress Terraform module and a helm based module.
Using the module is straight forward:
# require and configure provider
terraform {
required_providers {
kustomization = {
source = "kbst/kustomization"
}
}
}
provider "kustomization" {
alias = "example"
kubeconfig_path = "~/.kube/config"
}
# call module
module "example_nginx" {
providers = {
# we're using the alias provider we configured above
kustomization = kustomization.example
}
source = "kbst.xyz/catalog/nginx/kustomization"
version = "1.2.1-kbst.0" # find the latest version on https://www.kubestack.com/catalog/nginx
# the configuration here assumes you're using Terraform's default workspace
# use `terraform workspace list` to see the workspaces
configuration_base_key = "default"
configuration = {
default = {
replicas = [{
name = "ingress-nginx-controller"
count = 5
}]
}
}
}
The example module call uses kustomize's replicas
attribute to change the replicas of the Nginx ingress controller.
The module's (I have them for more than just Nginx) allow defining the kustomization as part of the module call. They also bundle an upstream release, and you control the version using the version attribute.
Documentation for all available kustomization attributes can be found on the Kubestack website.
I maintain these modules as part of Kubestack, my open-source framework for platform teams working with Terraform and Kubernetes.
Upvotes: 1
Reputation: 1978
Updated answer
resource "helm_release" "nginix-ingress" {
name = "nginix-ingress"
repository = "https://charts.bitnami.com/bitnami"
chart = "nginx"
namespace = "kube-system"
}
Upvotes: 2
Reputation: 11446
There is a nice tutorial Create an Application Gateway ingress controller in Azure Kubernetes Service. And you can check GitHub for Application Gateway Ingress Controller.
If you are using Terraform version 0.12 or higher you can use terraform provider kubernetes example.
As for the Terraform documentation you should check Data source kubernetes_ingress and Resource kubernetes_ingress.
If you provide more details I'll update the answer.
Upvotes: 1