Skip to content

Instantly share code, notes, and snippets.

View ruanbekker's full-sized avatar
🇿🇦

Ruan Bekker ruanbekker

🇿🇦
View GitHub Profile
@ruanbekker
ruanbekker / gitea-docker-compose.yml
Created December 28, 2020 19:53
gitlab and drone server on docker for ubuntu 20
version: "3.7"
services:
# https://docs.gitea.io/en-us/install-with-docker/
gitea:
image: gitea/gitea:1.12.4
# https://hub.docker.com/r/gitea/gitea/tags
container_name: gitea
environment:
- APP_NAME=Gitea
@ruanbekker
ruanbekker / envsubst_example.md
Created December 17, 2020 12:30
Replacing Environment Variables with envsubst
$ cat test.tmpl
Hi ${USER}, this is a ${ENVIRONMENT} environment
USER=ruan ENVIRONMENT=test envsubst '${USER},${ENVIRONMENT}' < test.tmpl
Hi ruan, this is a test environment
@ruanbekker
ruanbekker / index.html
Created December 11, 2020 22:18
index.html sample page
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<title>Sample Page</title>
</head>
<body>
<div class="container-fluid">
@ruanbekker
ruanbekker / 00_README.md
Created December 4, 2020 08:50
Loki absent_over_time workaround using AWS Lambda

Loki absent over time workaround

This is a workaround that works for my use-case when log content are not present withing a minute, using AWS Lambda and AWS CloudWatch Events

Setup:

  • AWS CloudWatch event triggers the Lambda every minute
  • Lambda uses the Loki API to search for logs, if nothing has been found it retries if still fails, it alerts
  • It alerts to slack.
@ruanbekker
ruanbekker / ec2_asg_launch_config_spot.md
Last active November 17, 2020 04:53
Create EC2 Spot Instance Launch Config and Auto Scaling Group with AWS CLI

Userdata:

$ cat userdata.txt
#!/bin/bash
CLUSTER_NAME="aws-qa-ecs"
ENVIRONMENT_NAME="qa"
INSTANCE_LIFECYCLE="spot"
MY_HOSTNAME="$(curl -s http://169.254.169.254/latest/meta-data/local-hostname)"
INSTANCE_ID="$(curl -s http://instance-data/latest/meta-data/instance-id)"
@ruanbekker
ruanbekker / userdata_ecs.txt
Created November 16, 2020 16:07
EC2 Userdata with Prometheus Node Exporter and Loki for ECS
#!/bin/bash
AWS_ACCOUNT="dev"
CLUSTER_NAME="aws-qa-ecs"
ENVIRONMENT_NAME="qa"
NODE_EXPORTER_VERSION="1.0.1"
NODE_EXPORTER_USER="node_exporter"
MY_HOSTNAME="$(curl -s http://169.254.169.254/latest/meta-data/local-hostname)"
INSTANCE_ID="$(curl -s http://instance-data/latest/meta-data/instance-id)"
INSTANCE_LIFECYCLE="$(curl -s http://169.254.169.254/latest/meta-data/instance-life-cycle)"
REGION="$(curl -s http://instance-data/latest/meta-data/placement/availability-zone | rev | cut -c 2- | rev)"
@ruanbekker
ruanbekker / aws_ec2_odemand_spot.md
Last active November 16, 2020 15:33
AWS Price Difference between On-Demand and Spot

OnDemand:

$ curl -s https://raw.githubusercontent.com/powdahound/ec2instances.info/master/www/instances.json | jq -r '.[] | select(.instance_type == "t2.micro") | .pricing."eu-west-1".linux.ondemand'
0.0126

Spot:

@ruanbekker
ruanbekker / loki_logcli_promtail.md
Last active January 22, 2024 07:52
Quick Demonstration how to Pipe to Loki with Loki, LogCLI and Promtail

Provision a VM with Multipass:

$ multipass shell
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic
@ruanbekker
ruanbekker / kvm_host_one_provider.md
Created October 6, 2020 23:42
Setup a KVM Host on OneProvider

Update and install cpu-checker to see if we can use hardware virtualization:

$ apt update && apt upgrade -y
$ apt install cpu-checker -y

Test with kvm-ok:

@ruanbekker
ruanbekker / convert_ssh2_to_openssh.md
Last active October 6, 2020 12:41
Convert SSH2 format public keys to OpenSSH format

SSH2 format will look like this:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20201005"
AAAA
....
abcdef==
---- END SSH2 PUBLIC KEY ----