Posts

Scale multiple ECS services at once

You use the following bash script I wrote to scale multiple ECS services at once: Prerequisite - AWS CLI [1] - An IAM account that has permission to update or scale ECS services - A text file that contains all the ECS service names, each line contains 1 service name. For example: service1 service2 ... Usage ./mass_scale_ecs_svc.sh <cluster name> <path to the ECS service names text file> <desired count, e.g., 0> References: [1]  https://aws.amazon.com/cli/

Create a sock proxy to a private network

Last week, I wrote a bash script that can be used to create a sock proxy that connects my computer and a private network via a bastion server (the bastion server is a server that sitting inside a private network that I can ssh into using a pem key). Usage: ./gen_sockproxy.sh /path/to/sshkey.pem <bastion_username> <bastion_address> It will output the sock proxy address. For example:  socks5://localhost:13000

Add MetalLB to MicroK8S

Image
There is a question that pops up inside my head every time I work with Kubernetes [1], " Why the hell does it not implement a network load balancer? ". It did have network load balancers but tied to public cloud providers (e.g., AWS, GCP, etc.). What if I want to run Kubernetes clusters in my private clouds or even in my bare-metal infrastructures? Fortunately, I found  MetalLB [2]. "MetalLB hooks into your Kubernetes cluster, and provides a network load-balancer implementation. In short, it allows you to create Kubernetes services of type “LoadBalancer” in clusters that don’t run on a cloud provider, and thus cannot simply hook into paid products to provide load-balancers." ~MetalLB documentations. So, whenever I spin up a new Kubernetes cluster in my bare-metal infrastructures (or for my MicroK8S [4] clusters), I normally have to deploy MetalLB and with Layer 2 configuration as depicted in figure 1. There are also other configurations such as BGP, automatic ...

To get a random available port in your *nix-based machine

For example, If I want to get a random port from the 3000-3999 port pool, I would run the following command in the terminal: comm -23 <(seq 3000 3999 | sort) <(ss -tan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1

Manipulate your yaml file with yq

I like to play with bash shell especially when I have to manipulate template files of some sort on the go (dynamically). yq is a great tool I just figured out that can help me to generate SAM [1] template.yaml file based on some business logic. The great thing about yq is that I don't have to install it to be able to run it with the help of docker. So, add this to my bash script yq ( ) { docker run --rm -i -v ${PWD} :/workdir mikefarah/yq yq $@ } and than I can use yq as if I installed it, for example: yq d template.yaml 'Resources.AllOutboundSG' Read [2] to know more about how to use yq. References: [1]  https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html [2]  https://mikefarah.gitbook.io/yq/

How to get the list of lambda functions filtered by runtime (or any other attrib) using aws-cli

Pretty easy. For example, if I want to get the list of lambda functions that use the nodejs8.10 runtime, I can do something like: aws lambda list-functions --query 'Functions[?Runtime==`nodejs8.10`].[FunctionName]' --output text | tr '\r\n' ' '

Exclude a service from being auto sidecar injected by istio

As you may know, you can enable automatic sidecar injection for a specific namespace with istio: kubectl label namespace ABC istio-injection=enabled It means that every new service deployed in the ABC namespace will be injected with an Envoy sidecar. In case you don't want a specific service such as MyService to be controlled by Istio, you can set the annotation ' sidecar.istio.io/inject ' to ' false '. For example: References: https://istio.io/docs/reference/config/annotations/