• Stars
    star
    170
  • Rank 223,357 (Top 5 %)
  • Language HCL
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create infrastructure with Terraform and AWS, install OpenShift. Party!

terraform-aws-openshift

CircleCI

This project shows you how to set up OpenShift on AWS using Terraform. This the companion project to my article Get up and running with OpenShift on AWS.

OpenShift Sample Project

I am also adding some 'recipes' which you can use to mix in more advanced features:

Index

Overview

Terraform is used to create infrastructure as shown:

Network Diagram

Once the infrastructure is set up an inventory of the system is dynamically created, which is used to install the OpenShift Origin platform on the hosts.

Prerequisites

You need:

  1. Terraform (0.12 or greater) - brew update && brew install terraform
  2. An AWS account, configured with the cli locally -
if [[ "$unamestr" == 'Linux' ]]; then
        dnf install -y awscli || yum install -y awscli
elif [[ "$unamestr" == 'FreeBSD' ]]; then
        brew install -y awscli
fi

Creating the Cluster

Create the infrastructure first:

# Make sure ssh agent is on, you'll need it later.
eval `ssh-agent -s`

# Create the infrastructure.
make infrastructure

You will be asked for a region to deploy in, use us-east-1 or your preferred region. You can configure the nuances of how the cluster is created in the main.tf file. Once created, you will see a message like:

$ make infrastructure
var.region
  Region to deploy the cluster into

  Enter a value: ap-southeast-1

...

Apply complete! Resources: 20 added, 0 changed, 0 destroyed.

That's it! The infrastructure is ready and you can install OpenShift. Leave about five minutes for everything to start up fully.

Installing OpenShift

To install OpenShift on the cluster, just run:

make openshift

You will be asked to accept the host key of the bastion server (this is so that the install script can be copied onto the cluster and run), just type yes and hit enter to continue.

It can take up to 30 minutes to deploy. If this fails with an ansible not found error, just run it again.

Once the setup is complete, just run:

make browse-openshift

To open a browser to admin console, use the following credentials to login:

Username: admin
Password: 123

Accessing and Managing OpenShift

There are a few ways to access and manage the OpenShift Cluster.

OpenShift Web Console

You can log into the OpenShift console by hitting the console webpage:

make browse-openshift

# the above is really just an alias for this!
open $(terraform output master-url)

The url will be something like https://a.b.c.d.xip.io:8443.

The Master Node

The master node has the OpenShift client installed and is authenticated as a cluster administrator. If you SSH onto the master node via the bastion, then you can use the OpenShift client and have full access to all projects:

$ make ssh-master # or if you prefer: ssh -t -A ec2-user@$(terraform output bastion-public_ip) ssh master.openshift.local
$ oc get pods
NAME                       READY     STATUS    RESTARTS   AGE
docker-registry-1-d9734    1/1       Running   0          2h
registry-console-1-cm8zw   1/1       Running   0          2h
router-1-stq3d             1/1       Running   0          2h

Notice that the default project is in use and the core infrastructure components (router etc) are available.

You can also use the oadm tool to perform administrative operations:

$ oadm new-project test
Created project test

The OpenShift Client

From the OpenShift Web Console 'about' page, you can install the oc client, which gives command-line access. Once the client is installed, you can login and administer the cluster via your local machine's shell:

oc login $(terraform output master-url)

Note that you won't be able to run OpenShift administrative commands. To administer, you'll need to SSH onto the master node. Use the same credentials (admin/123) when logging through the commandline.

Connecting to the Docker Registry

The OpenShift cluster contains a Docker Registry by default. You can connect to the Docker Registry, to push and pull images directly, by following the steps below.

First, make sure you are connected to the cluster with The OpenShift Client:

oc login $(terraform output master-url)

Now check the address of the Docker Registry. Your Docker Registry url is just your master url with docker-registry-default. at the beginning:

% echo $(terraform output master-url)
https://54.85.76.73.xip.io:8443

In the example above, my registry url is https://docker-registry-default.54.85.76.73.xip.io. You can also get this url by running oc get routes -n default on the master node.

You will need to add this registry to the list of untrusted registries. The documentation for how to do this here https://docs.docker.com/registry/insecure/. On a Mac, the easiest way to do this is open the Docker Preferences, go to 'Daemon' and add the address to the list of insecure regsitries:

Docker Insecure Registries Screenshot

Finally you can log in. Your Docker Registry username is your OpenShift username (admin by default) and your password is your short-lived OpenShift login token, which you can get with oc whoami -t:

% docker login docker-registry-default.54.85.76.73.xip.io -u admin -p `oc whoami -t`
Login Succeeded

You are now logged into the registry. You can also use the registry web interface, which in the example above is at: https://registry-console-default.54.85.76.73.xip.io

Atomic Registry Screenshot

Persistent Volumes

The cluster is set up with support for dynamic provisioning of AWS EBS volumes. This means that persistent volumes are supported. By default, when a user creates a PVC, an EBS volume will automatically be set up to fulfil the claim.

More details are available at:

No additional should be required for the operator to set up the cluster.

Note that dynamically provisioned EBS volumes will not be destroyed when running terrform destroy. The will have to be destroyed manuallly when bringing down the cluster.

Additional Configuration

The easiest way to configure is to change the settings in the ./inventory.template.cfg file, based on settings in the OpenShift Origin - Advanced Installation guide.

When you run make openshift, all that happens is the inventory.template.cfg is turned copied to inventory.cfg, with the correct IP addresses loaded from terraform for each node. Then the inventory is copied to the master and the setup script runs. You can see the details in the makefile.

Choosing the OpenShift Version

Currently, OKD 3.11 is installed.

To change the version, you can attempt to update the version identifier in this line of the ./install-from-bastion.sh script:

git clone -b release-3.11 https://github.com/openshift/openshift-ansible

However, this may not work if the version you change to requires a different setup. To allow people to install earlier versions, stable branches are available. Available versions are listed here.

Version Status Branch
3.11 Tested successfull release/okd-3.11
3.10 Tested successfully release/okd-3.10
3.9 Tested successfully release/ocp-3.9
3.8 Untested
3.7 Untested
3.6 Tested successfully release/openshift-3.6
3.5 Tested successfully release/openshift-3.5

Destroying the Cluster

Bring everything down with:

terraform destroy

Resources which are dynamically provisioned by Kubernetes will not automatically be destroyed. This means that if you want to clean up the entire cluster, you must manually delete all of the EBS Volumes which have been provisioned to serve Persistent Volume Claims.

Makefile Commands

There are some commands in the makefile which make common operations a little easier:

Command Description
make infrastructure Runs the terraform commands to build the infra.
make openshift Installs OpenShift on the infrastructure.
make browse-openshift Opens the OpenShift console in the browser.
make ssh-bastion SSH to the bastion node.
make ssh-master SSH to the master node.
make ssh-node1 SSH to node 1.
make ssh-node2 SSH to node 2.
make sample Creates a simple sample project.
make lint Lints the terraform code.

Pricing

You'll be paying for:

  • 1 x m4.xlarge instance
  • 2 x t2.large instances

Recipes

Your installation can be extended with recipes.

Splunk

You can quickly add Splunk to your setup using the Splunk recipe:

Splunk Screenshot

To integrate with splunk, merge the recipes/splunk branch then run make splunk after creating the infrastructure and installing OpenShift:

git merge recipes/splunk
make infracture
make openshift
make splunk

There is a full guide at:

http://www.dwmkerr.com/integrating-openshift-and-splunk-for-logging/

You can quickly rip out container details from the log files with this filter:

source="/var/log/containers/counter-1-*"  | rex field=source "\/var\/log\/containers\/(?<pod>[a-zA-Z0-9-]*)_(?<namespace>[a-zA-Z0-9]*)_(?<container>[a-zA-Z0-9]*)-(?<conatinerid>[a-zA-Z0-9_]*)" | table time, host, namespace, pod, container, log

Troubleshooting

Image pull back off, Failed to pull image, unsupported schema version 2

Ugh, stupid OpenShift docker version vs registry version issue. There's a workaround. First, ssh onto the master:

$ ssh -A ec2-user@$(terraform output bastion-public_ip)

$ ssh master.openshift.local

Now elevate priviledges, enable v2 of of the registry schema and restart:

sudo su
oc set env dc/docker-registry -n default REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_ACCEPTSCHEMA2=true
systemctl restart origin-master.service

You should now be able to deploy. More info here.

OpenShift Setup Issues

TASK [openshift_manage_node : Wait for Node Registration] **********************
FAILED - RETRYING: Wait for Node Registration (50 retries left).

fatal: [node2.openshift.local -> master.openshift.local]: FAILED! => {"attempts": 50, "changed": false, "failed": true, "results": {"cmd": "/bin/oc get node node2.openshift.local -o json -n default", "results": [{}], "returncode": 0, "stderr": "Error from server (NotFound): nodes \"node2.openshift.local\" not found\n", "stdout": ""}, "state": "list"}
        to retry, use: --limit @/home/ec2-user/openshift-ansible/playbooks/byo/config.retry

This issue appears to be due to a bug in the kubernetes / aws cloud provider configuration, which is documented here:

#40

At this stage if the AWS generated hostnames for OpenShift nodes are specified in the inventory, then this problem should disappear. If internal DNS names are used (e.g. node1.openshift.internal) then this issue will occur.

Unable to restart service origin-master-api

Failure summary:


  1. Hosts:    ip-10-0-1-129.ec2.internal
     Play:     Configure masters
     Task:     restart master api
     Message:  Unable to restart service origin-master-api: Job for origin-master-api.service failed because the control process exited with error code. See "systemctl status origin-master-api.service" and "journalctl -xe" for details.

Developer Guide

This section is intended for those who want to update or modify the code.

CI

CircleCI 2 is used to run builds. You can run a CircleCI build locally with:

make circleci

Currently, this build will lint the code (no tests are run).

Linting

tflint is used to lint the code on the CI server. You can lint the code locally with:

make lint

References

More Repositories

1

hacker-laws

💻📖 Laws, Theories, Principles and Patterns that developers will find useful. #hackerlaws
Shell
25,245
star
2

sharpshell

SharpShell makes it easy to create Windows Shell Extensions using the .NET Framework.
C#
1,478
star
3

sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
C#
720
star
4

consolecontrol

ConsoleControl is a C# class library that lets you embed a console in a WinForms or WPF application.
C#
672
star
5

effective-shell

Text, samples and website for my 'Effective Shell' series.
JavaScript
649
star
6

angular-modal-service

Modal service for AngularJS - supports creating popups and modals via a service.
JavaScript
629
star
7

app-icon

Icon management for Mobile Apps. Create icons, generate all required sizes, label and annotate. Supports Native, Cordova, React Native, Xamarin and more. Inspired by cordova-icon.
Java
563
star
8

wait-port

Simple binary to wait for a port to open. Useful for docker-compose and general server side activities.
JavaScript
321
star
9

docker-dynamodb

It's DynamoDB - in Docker!
Shell
230
star
10

spaceinvaders

Classic Space Invaders game written in JavaScript as a learning exercise.
JavaScript
189
star
11

node-docker-microservice

Demonstrates how to build a testable, deployable, scalable microservice with NodeJS and Docker.
JavaScript
166
star
12

dotfiles

My personal setup. Vim, Tmux, Shells, etc.
Shell
77
star
13

mongo-monitor

CLI to monitor the status of a MongoDB cluster real-time 📈
JavaScript
77
star
14

crosswords-js

Tiny, lightweight crossword control for the web.
JavaScript
57
star
15

terraform-consul-cluster

Demonstrates how to create a resilient Consul cluster on AWS, using Terraform. Companion to my article on dwmkerr.com.
HCL
56
star
16

glmnet

GlmNet is a .NET version of the excellent OpenGL Mathematics library (GLM).
C++
52
star
17

starfield

A nice starfield background using built using HTML and vanilla JavaScript as a learning exercise.
HTML
49
star
18

architecture-as-code

A project to help define architecture logically as code, and generate living, interactive diagrams.
JavaScript
47
star
19

linux-kernel-module

A simple Linux Kernel Module, written as a learning exercise.
C
30
star
20

app-splash

Automatic splash screen generation and resizing for Mobile Apps. Supports Native, React Native, Cordova, Xamarin and more. The little brother of 'app-icon'.
Java
29
star
21

angular-memory-leaks

A small and leaky AngularJS application used to demonstrate how to identify, analyse and resolve memory leaks in JavaScript applications. A companion to the write-up at www.dwmkerr.com/fixing-memory-leaks-in-angularjs-applications
JavaScript
28
star
22

gacmanager

GAC Manager is an open source project that comes in two parts - a fully functional application to manage the Global Assembly Cache on your computer, and a C# API to allow you to manage the GAC yourself.
C#
25
star
23

langtonsant

Langton's Ant implemented in Javascript
JavaScript
23
star
24

sil

Sil is an application and addin for Visual Studio that lets you disassemble your C# code.
C#
21
star
25

file-format-wavefront

A simple .NET library to load data from Wavefront *.obj and *.mlb files.
C#
20
star
26

java-maven-standard-version-sample

This simple module demos how to use Conventional Commits, Git Hooks to enforce Conventional Commits and Semantic Versioning in a Java project built with Maven.
Shell
18
star
27

beautifully-simple-app-ci

This repository demonstrates some beautifully simple techniques for handling CI and CI for mobile apps. These techniques are appliclable to many mobile technologies and development platforms and compliment many different CI/CD toolchains.
Makefile
17
star
28

google-it

Command line tool to quickly look something up on Google!
Go
16
star
29

docker-terraform-ci

A base image for working with Terraform in CI scenarios. Provides Terraform, tflint, AWS CLI, etc.
Dockerfile
14
star
30

learn-a-language

A set of ideas and projects to work on that are great to help you learn a programming language.
14
star
31

dotnet-windows-registry

A simple, unit and integration test friendly wrapper around the Windows Registry, which is 100% compliant with the existing Microsoft.Win32.Registry package.
C#
12
star
32

react-es6-starter

A simple starter template for a React ES6 web app
JavaScript
12
star
33

lex-starter-kit

A starter kit for building chatbots using AWS Lex and Lambda.
Shell
11
star
34

switch

Switch is an Addin for Visual Studio that lets you quickly switch between related files, such as *.cpp and *.h or XAML and code-behind.
C#
9
star
35

svg-smile

Procedurally animated smiley face with SVG and pure JavaScript 😀🙂😐🙁☹️
HTML
8
star
36

node-imagemagick-cli

Access the ImageMagick CLI tools from Node. No dependencies, cross-platform, with support for ImageMagick 6 and 7.
JavaScript
8
star
37

effective-container-engineering

Practical tips and patterns for building good container citizens
JavaScript
7
star
38

terraform-aws-vpc-example

An example terraform module to create an AWS VPC with a cluster of web servers.
HCL
7
star
39

chatgpt-diagrams-extension

A Chrome browser extension that renders diagrams in the ChatGPT website inline.
HTML
7
star
40

lex-chat

A simple CLI for chatting to AWS Lex ChatBots. Great for development!
JavaScript
6
star
41

jsonclient

JsonClient .NET is a lightweight .NET class library that lets you access Json web services
C#
6
star
42

git-speed

Speed up your git flow with these advanced techniques.
Shell
6
star
43

docs

Useful guides, documents, snippets for working with tech.
Shell
5
star
44

firekeys

FireKeys is a Windows Application that lets you assign hotkeys to your favourite programs, URLs or actions.
C#
5
star
45

java-gradle-standard-version-sample

This simple module demos how to use Conventional Commits, Git Hooks to enforce Conventional Commits and Semantic Versioning in a Java project built with Maven.
Java
5
star
46

mongo-connection-string

Handle mongodb connection strings with ease.
JavaScript
4
star
47

makefile-help

A simple snippet that allows you to quickly add a 'help' command to a Makefile to show command documentation.
Shell
4
star
48

better-specs

Great specs can be in markdown.
4
star
49

microservices-playground

☁️🐳 Spin up microservice platforms on the cloud in seconds - use it to evaluate them or try new technologies!
JavaScript
4
star
50

apex

C#
3
star
51

ContentEditableMvc

ContentEditableMvc is a small library for ASP MVC 4 web pages that lets you use the power of the HTML5 contenteditable attribute and Ajax to update content from the client.
C#
3
star
52

docker-shells

A Debian Image will the most popular shells pre-installed. Useful for comparing features between shells.
Makefile
3
star
53

dwmkerr.com

The 'dwmkerr.com' website content and setup. Static site managed with Hugo.
JavaScript
3
star
54

vsix-tools

A set of Powershell functions to help with vsix files.
PowerShell
3
star
55

effective-shell-installer

This is the install script for the https://effective-shell.com samples. This repo hosts the https://effective.sh installer.
Shell
3
star
56

QuickAccent

Windows utility to allow quick selection of accents and symbols to the clipboard.
C#
3
star
57

effective-nodejs-debugging

Presentation, code samples and notes for a talk at JSChannel 2016
HTML
3
star
58

html5base

My personal preferences for a base HTML5 page - includes a css reset and some minor typography tweaks, as well as hyperlink styling.
CSS
2
star
59

terraform-aws-ecs-cluster

Build an Amazon Elastic Container Services Cluster with Terraform.
HCL
2
star
60

dotnet-com-admin

The COM Admin library provides APIs to manage the installation and registration of .NET Framework and .NET Core COM Servers and Shell Extensions
C#
2
star
61

terraform-aws-kubernetes

Create infrastructure with Terraform and AWS, install Kubernetes. Party! http://www.dwmkerr.com/get-up-and-run…
HCL
2
star
62

microservice-zapp

A super simple microservice I often use when demoing docker. Spits out quotes from Zapp Brannigan!
Python
1
star
63

deusnovum

Deus Novum is an HTML5/JS game that lets you take control of a Universe - manipulate time, space and physics to complete challenges.
JavaScript
1
star
64

pythonexperiments

A set of experiments in Python, good for learning.
Python
1
star
65

fsharpexperiments

A general repo for F# projects as learning exercises.
F#
1
star
66

puzlog

Hobby project. Track crossword progress.
HTML
1
star
67

node-configuration

Simple configuration for Node applications, load from files, environment variables or parameters.
1
star
68

template-nodejs-module

A template for a Node.js module that has basic standards for linting, testing, build pipelines, NPM deployment, documentation and contributors.
Shell
1
star
69

seed-node

Starter project for Node.js.
JavaScript
1
star
70

on

A simple tool which helps when working with environment variables, devops and 12 factor apps.
JavaScript
1
star
71

homebrew-tools

A Homebrew Tap for tools which I maintain and publish.
1
star
72

slack-backend

A demo repository showing how Slack can be useful when building backend systems
1
star
73

app-version

Version management for Mobile Apps. Simple tool to set version for Native, React Native, Cordova, Xamarin and more.
JavaScript
1
star