Skip to content

Latest commit

 

History

History

azure-py-aks-diagnosticsetting

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Azure Kubernetes Service (AKS) Cluster using the native Azure Provider and DiagnosticSetting in Python

This example deploys an AKS cluster, creates an Azure Active AD application, creates a Service Principal and sets credentials to manage access to the cluster. We also turn on DiagnosticSettings on the AKS cluster.

Deploying the App

  1. Initialize a new stack called dev via pulumi stack init.

    pulumi stack init dev
  2. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):

    az login
  3. Create a Python virtualenv, activate it, and install dependencies:

    This installs the dependent packages for our Pulumi program.

    python3 -m venv venv
    source venv/bin/activate
    pip3 install -r requirements.txt
  4. Set the confi values via pulumi config set.

    Here are Azure regions see this infographic for a list of available regions)

    pulumi config set azure-native:location eastus2
  5. Run pulumi up to preview and deploy changes: You must select y to continue

    pulumi up

    Results

    View Live: https://app.pulumi.com/shaht/azure-py-aks-diagnosticsetting/dev/updates/60
    
     Type                                             Name                                   Status      Info
    +   pulumi:pulumi:Stack                              azure-py-aks-diagnosticsetting-dev     created     1 warning
    +   ├─ azuread:index:Application                     demodiag-azuread-apps                  created     
    +   ├─ random:index:RandomPassword                   demodiag-randompassword                created     
    +   ├─ tls:index:PrivateKey                          demodiag-ssh-key                       created     
    +   ├─ azure-native:resources:ResourceGroup          demodiag-rg                            created     
    +   ├─ azure-native:storage:StorageAccount           demodiagsa                             created     
    +   ├─ azuread:index:ServicePrincipal                demodiag-ad-serviceprincipal           created     
    +   ├─ azuread:index:ServicePrincipalPassword        demodiag-serviceprincipalpassword      created     1 warning
    +   ├─ azure-native:containerservice:ManagedCluster  demodiag-azure-aks                     created     
    +   └─ azure-native:insights:DiagnosticSetting       demodiag-diagnostic-control-plane-log  created     
    
    Diagnostics:
    azuread:index:ServicePrincipalPassword (demodiag-serviceprincipalpassword):
        warning: urn:pulumi:dev::azure-py-aks-diagnosticsetting::azuread:index/servicePrincipalPassword:ServicePrincipalPassword::demodiag-serviceprincipalpassword verification warning: Deprecated Attribute
    
    pulumi:pulumi:Stack (azure-py-aks-diagnosticsetting-dev):
        warning: value is deprecated: In version 2.0 of the AzureAD provider, this attribute will become read-only as it will no longer be possible to specify a password value. It will be generated by Azure Active Directory and persisted to state for reuse in your Terraform configuration.
    
    Outputs:
        ad_app_name            : "0f86d9e4-1990-40d7-be39-cf25b788edc0"
        ad_sp_display_name     : "demodiag-azuread-apps"
        diagnostic_setting_id  : "[secret]"
        diagnostic_setting_name: "demodiag-diagnostic-control-plane-logaf3a4dbf"
        kubeconfig             : "[secret]"
        managed_cluster_name   : "demodiag-azure-akse5175902"
        managed_cluster_uri    : "[secret]"
        resource_group_name    : "demodiag-rg0b6f1569"
        storage_account_id     : "[secret]"
        storage_account_name   : "demodiagsa89363946"
    
    Resources:
        + 10 created
    
    Duration: 12m7s
  6. View the outputs.

    pulumi stack output

    Results

    Current stack outputs (10):
     OUTPUT                   VALUE
     ad_app_name              0f86d9e4-1990-40d7-be39-cf25b788edc0
     ad_sp_display_name       demodiag-azuread-apps
     diagnostic_setting_id    [secret]
     diagnostic_setting_name  demodiag-diagnostic-control-plane-logaf3a4dbf
     kubeconfig               [secret]
     managed_cluster_name     demodiag-azure-akse5175902
     managed_cluster_uri      [secret]
     resource_group_name      demodiag-rg0b6f1569
     storage_account_id       [secret]
     storage_account_name     demodiagsa89363946

    If you need to see the values that are secret, you will have to do the following

    pulumi stack output --show-secrets
  7. You can save this kubeconfig to a file and use kubectl via command line:

    pulumi stack output kubeconfig --show-secrets > kubeconfig

    Once you have this file in hand, you can interact with your new cluster as usual via kubectl:

    export KUBECONFIG=$PWD/kubeconfig 
    kubectl version
    kubectl get nodes
  8. Clean up

    pulumi destroy -y
  9. Remove. This will remove the Pulumi.dev.yaml file also

    pulumi stack rm dev -y