Skip to content

Instantly share code, notes, and snippets.

@leandrosiow
leandrosiow / tail-coredns.sh
Created February 25, 2020 04:55
Here is a simple to tail coredns logs
kubectl -n kube-system logs -f deployment/coredns --all-containers=true --since=5s
@leandrosiow
leandrosiow / coredns-antiaffintiy-preferred.yaml
Last active November 17, 2020 19:45
Using podAntiAffinity(preferredDuringSchedulingIgnoredDuringExecution) to preferably avoid scheduling coredns pods on a node where another coredns pods is already running.
apiVersion: apps/v1
kind: Deployment
metadata:
name: coredns
namespace: kube-system
labels:
k8s-app: kube-dns
kubernetes.io/name: "CoreDNS"
eks.amazonaws.com/component: coredns
spec:
@leandrosiow
leandrosiow / coredns-podAntiAffinity-required.yaml
Last active November 17, 2020 19:55
Using podAntiAffinity(requiredDuringSchedulingIgnoredDuringExecution) to completely avoid scheduling coredns pods on a node where another coredns pods is already running
apiVersion: v1
kind: ServiceAccount
metadata:
name: coredns
namespace: kube-system
labels:
eks.amazonaws.com/component: coredns
k8s-app: kube-dns
---
apiVersion: rbac.authorization.k8s.io/v1beta1
@leandrosiow
leandrosiow / detect-os.sh
Created February 19, 2020 04:12
How to detect the OS from a Bash script?
if [[ "$OSTYPE" == "linux-gnu" ]]; then
# ...
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
elif [[ "$OSTYPE" == "win32" ]]; then
# I'm not sure this can happen.
@leandrosiow
leandrosiow / userdata.ps
Last active February 11, 2020 05:01
Here is a workaround for ECS Windows GitHub Issue: [Windows Credential Proxy Unavailable after EC2 Stop/Start #2135] https://github.com/aws/amazon-ecs-agent/issues/2135
<powershell>
C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 -Schedule
netsh interface portproxy delete v4tov4 80 169.254.170.2 | out-null
[Environment]::SetEnvironmentVariable('ECS_DISABLE_METRICS', 'false', 'Machine')
[Environment]::SetEnvironmentVariable('ECS_ENABLE_AWSLOGS_EXECUTIONROLE_OVERRIDE', $TRUE, 'Machine')
Initialize-ECSAgent -Cluster Windows -EnableTaskIAMRole -LoggingDrivers '["json-file","awslogs"]'
</powershell>
@leandrosiow
leandrosiow / choco-install-awscli.ps
Created February 11, 2020 04:08
This script install awscli with Chocolatey.
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install awscli -y
$env:Path += ";C:\Program Files\Amazon\AWSCLI\bin"
@leandrosiow
leandrosiow / ec2ssh.sh
Last active February 9, 2020 22:06
This little script helps you SSH to your EC2 instance via an instance-id. You will still need to have your pem files in the .ssh folder.
ec2ssh()
{
if [[ ! -z "$1" ]]; then
# echo "cfn"
INSTANCE_ID_INPUT=$1
else
echo -n "Enter Instance ID: "
read INSTANCE_ID_INPUT
fi
@leandrosiow
leandrosiow / kubelet.service
Last active February 9, 2020 22:07
Here is an example of the kubelet service file created by eksctl
file that has been created by eksctl
```
# /etc/systemd/system/kubelet.service
# eksctl-specific systemd drop-in unit for kubelet, for Amazon Linux 2 (AL2)
[Service]
# Local metadata parameters: REGION, AWS_DEFAULT_REGION
EnvironmentFile=/etc/eksctl/metadata.env
# Global and static parameters: CLUSTER_DNS, NODE_LABELS, NODE_TAINTS
EnvironmentFile=/etc/eksctl/kubelet.env
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
After=docker.service
Requires=docker.service
[Service]
ExecStartPre=/sbin/iptables -P FORWARD ACCEPT
ExecStart=/usr/bin/kubelet --cloud-provider aws \
--config /etc/kubernetes/kubelet/kubelet-config.json \
@leandrosiow
leandrosiow / kubelet-config-all-options.json
Last active November 8, 2023 05:03
These are examples of kubelet-config.json files
{
"kind": "KubeletConfiguration",
"apiVersion": "kubelet.config.k8s.io/v1beta1",
"syncFrequency": "1m0s",
"fileCheckFrequency": "20s",
"httpCheckFrequency": "20s",
"address": "0.0.0.0",
"port": 10250,
"tlsCertFile": "/root/cdk/server.crt",
"tlsPrivateKeyFile": "/root/cdk/server.key",