GithubHelp home page GithubHelp logo

asmtal / acs-engine-terraform Goto Github PK

View Code? Open in Web Editor NEW

This project forked from daniel-rhoades/acs-engine-terraform

0.0 0.0 0.0 6 KB

Azure Container Service (ACS) Engine running K8s and provisioned by Terraform

HCL 100.00%

acs-engine-terraform's Introduction

acs-engine-terraform

Azure Container Service (ACS) Engine running K8s and provisioned by Terraform.

See my detailed article on Terraform, Kubernetes and Microsoft Azure to understand how to use it. But if you are feeling lazy, then do the following steps to get it working:

Some pre-requisites first:

Next, create a Terraform variables file (e.g. k8s.tfvars) with the following information:

azure_subscription_id = "<YOUR-AZURE-SUBSCRIPTION-ID-FOR-TERRAFORM>"
azure_tenant_id       = "<YOUR-AZURE-TENANT-ID-FOR-TERRAFORM>"
azure_client_id       = "<YOUR-AZURE-CLIENT-ID-FOR-TERRAFORM>"
azure_client_secret   = "<YOUR-AZURE-CLIENT-SECRET-FOR-TERRAFORM>"

dns_prefix                      = "<YOUR-DNS-PREFIX>"
ssh_key                         = "<YOUR-SSH-KEY>"

If you followed Terraform's Azure setup guide, then you'll already have the values for each of the azure_* variables, so replace those placeholders. The other substitutions should be made as follows:

  • YOUR-DNS-PREFIX - Enter anything you like to prefix the DNS record for your cluster, e.g dans-k8s-example
  • YOUR-SSH-KEY - The PEM encoded public version of the key you generated, e.g. just get the output from cat ~/.ssh/id_rsa.pub.

That should do it, so just run it now:

$ terraform apply -var-file="k8s.tfvars"

If the provisioning takes a long time, you might get an error, which will likely be due to a timeout. If you can see 16 items in the resource group in the Azure portal and the rest of the steps in the guide work, it should be all fine.

We can now remotely connect to the cluster, to get the K8s remote configuration it's easier just to grab this from the master like so:

$ scp -i <SSH-KEY> azureuser@<MASTER-PUBLIC-IP>:~/.kube/config ~/.kube/config

In the above example you'll need to replace the placeholder values:

  • SSH-KEY - Private SSH key matching the public key given to the cluster during setup, e.g. ~/.ssh/id_rsa;
  • MASTER-PUBLIC-IP - Find the master VM in the Azure portal, the public IP address will be attached to it.

Then test the connection using kubectl get nodes, which should return a list of our 2 nodes (1 master and 1 worker). You're done, you can now deploy your own pods, for example:

$ kubectl run nginx --image nginx
$ kubectl expose deployments nginx --port=80 --type=LoadBalancer
$ kubectl get services

Wait until the nginx service has been given an external (public) IP. In the background K8s is actually creating an Azure Load Balancer for this purpose (you can see it in the Azure portal). Then simply confirm it works by running curl http://<EXTERNAL-IP>, you should get the standard nginx welcome page. If curl just hangs then you probably forgot to manually fix that route I talked about above ;)

The lazy way to delete the setup when you are done is run:

$ az group delete --name "k8sexample"

You can't just run terraform apply -var-file="k8s.tfvars" unfortunately, because the setup of the K8s cluster via the ACS Engine is a bit of a hack at the moment. Also, you might be best to manually delete k8s_rendered.json and the _output directory between runs. If Terraform messes up then also delete the terraform.tfstate/terraform.tfstate.backup files.

acs-engine-terraform's People

Contributors

daniel-rhoades avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.