Skip to content

Instantly share code, notes, and snippets.

View ruanbekker's full-sized avatar
🇿🇦

Ruan Bekker ruanbekker

🇿🇦
View GitHub Profile
@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 ----
@ruanbekker
ruanbekker / assume-role-policy.json
Created September 28, 2020 08:42 — forked from clstokes/assume-role-policy.json
Example: Terraform IAM Role
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
@ruanbekker
ruanbekker / terraform_kvm.md
Last active September 27, 2020 15:05
Terraform with KVM

Double check that security_driver = "none" is uncommented in /etc/libvirt/qemu.conf and restart sudo systemctl restart libvirtd for permission denied issue

cd /tmp/
mkdir -p ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.2/linux_amd64
wget https://github.com/dmacvicar/terraform-provider-libvirt/releases/download/v0.6.2/terraform-provider-libvirt-0.6.2+git.1585292411.8cbe9ad0.Ubuntu_18.04.amd64.tar.gz
tar -xvf terraform-provider-libvirt-0.6.2+git.1585292411.8cbe9ad0.Ubuntu_18.04.amd64.tar.gz
mv ./terraform-provider-libvirt  ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.2/linux_amd64/
@ruanbekker
ruanbekker / nginx-tuning.md
Created September 23, 2020 12:22 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.