GithubHelp home page GithubHelp logo

kryndex / terraform-packet-kubernetes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudnativelabs/terraform-packet-kubernetes

0.0 2.0 0.0 155 KB

Automated Kubernetes clusters on packet.net servers.

License: Apache License 2.0

HCL 91.94% Shell 8.06%

terraform-packet-kubernetes's Introduction

kube-metal

Join the chat at https://gitter.im/cloudnativelabs/kube-metal

kube-metal is a Terraform module that automates the creation of Kubernetes clusters and the infrastructure they run on.

Using Terraform you can quickly spin up Kubernetes clusters for CI and testing purposes, or for permanent use. kube-metal is designed to support testing core Kubernetes components such as kube-router.

Quickstart

kube-metal is highly configurable, but you can try it out in a few short steps.

Get kube-metal:

git clone https://github.com/cloudnativelabs/kube-metal.git
cd kube-metal

Use the get-providers.sh script to download and configure Terraform providers:

tools/get-providers.sh

Make sure you have a ~/.terraformrc that uses the new provider binaries. You can run the following:

cat <<EOF > ~/.terraformrc
providers {
  packet = "${GOPATH}/bin/terraform-provider-packet"
}
EOF

Provision the cluster on Packet.net. Be sure to have an account and API key created first.

terraform init
terraform apply

Update your hosts file for DNS resolution of the API controller

./tools/etc-hosts.sh

Enjoy!

./tools/kubectl.sh get nodes
./tools/kubectl.sh get pods --all-namespaces -o wide

This is perfect for scripting clusters for CI or demos. Read the getting started docs for more detailed provisioning steps.

How It Works

Terraform is used to provision and configure kubernetes nodes, and also generate TLS secrets for etcd/Kubernetes. Kubernetes apiserver and etcd are exposed on a public address by default so that CI systems and you can interact with them. These services are configured with TLS authentication/authorization to prevent unwanted access.

Bootkube is used to bootstrap the Kubernetes core components and start a self-hosted cluster.

Etcd is run self-hosted within the Kubernetes cluster by default, but this is easily configured to use an etcd server outside of Kubernetes.

Getting Started

These are detailed instructions to expand on the quickstart instructions.

Prerequisites

kube-metal uses unreleased features from Terraform providers. You can get them automatically with the provided get-providers.sh script.

tools/get-providers.sh

Then create a file ~/terraformrc and add the following:

providers {
  packet = "${GOPATH}/bin/terraform-provider-packet"
}

Configuration

There are many configuration options described in variables.tf. If you copy terraform.tfvars-example to a new file called terraform.tfvars then you can make your configuration changes persistent and Terraform will use them for all commands.

You will need to run terraform init before proceeding which downloads Terraform modules, and sets up the file backend store (terraform.tfstate).

Running kube-metal

Running terraform plan will show you what will be created. Running terraform apply will actually create the resources. In brief, it will:

  • Create an SSH key for itself and your CI system that will allow shell access to the nodes.
  • Boot your new nodes which get configured from a Container Linux Config that is converted to Ignition json and given to the provider as user-data. This config is available to view at templates/node.yaml in this repo.
  • Generated all assets and secrets needed for Bootkube, and copies them to the nodes as needed.
  • Starts a kubelet service on all nodes, and Bootkube on one node to begin the cluster bootstrapping process.

Accessing The Cluster

/etc/hosts DNS Setup

Due to the TLS security mechanisms in place, you must access a kube-metal provisioned cluster via the DNS name that was given to the controller node.

A script is provided that will add/replace the hosts file entry for you.

$ ./etc-hosts.sh
147.75.77.43 controller-01.test.kube-router.io
INFO: Removing above host file entry.
INFO: Appending the following host entry to your hosts file.
147.75.77.43 controller-01.test.kube-router.io

Alternatively you can use the host entries in the terraform output to manually update your hosts file or DNS server.

# Get the hosts file entries and append them to /etc/hosts
terraform output hosts_file_entries | sudo tee -a /etc/hosts

To see all available output variables run terraform output.

kubectl.sh

We've included a convenient kubectl.sh wrapper that runs kubectl with all the options needed to access your cluster baked right in.

./kubectl.sh get pods --all-namespaces

The kubeconfig is available under assets/auth/kubeconfig for use with the usual kubectl command.

# Backup a previous kubeconfig
mv ~/.kube/config ~/.kube/config-$(date --utc --iso-8601=seconds)

# Go into the kube-metal directory
cd kube-metal

# Option 1
ln -s "${PWD}/assets/auth/kubeconfig" ~/.kube/config
kubectl get nodes

# Option 2
KUBECONFIG="${PWD}/assets/auth/kubeconfig" kubectl get nodes

Cleaning Up

Run terraform destroy

terraform-packet-kubernetes's People

Contributors

bzub avatar gitter-badger avatar

Watchers

 avatar  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.