Pular para o conteúdo principal

Restoring Kubernetes 1.18 cluster after moving to aws

· Leitura de um minuto
export K8S_NODE_IP=
systemctl disable docker kubelet
systemctl stop docker kubelet

mv /etc/kubernetes /etc/kubernetes-backup
mv /var/lib/kubelet /var/lib/kubelet-backup

mkdir /etc/kubernetes/kubeadm -p
cp -r /etc/kubernetes-backup/pki /etc/kubernetes
rm -f /etc/kubernetes/pki/{apiserver.*,etcd/peer.*}
cp /etc/kubernetes-backup/kubeadm/kubeadm-config.yaml /etc/kubernetes/kubeadm/
rm -f ~/.kube/config

systemctl start docker

echo "KUBELET_EXTRA_ARGS=\"--node-ip=$K8S_NODE_IP\"" > /etc/sysconfig/kubelet

kubeadm init --config /etc/kubernetes/kubeadm/kubeadm-config.yaml --ignore-preflight-errors=DirAvailable--var-lib-etcd

cp /etc/kubernetes/admin.conf ~/.kube/config

kubectl cluster-info

kubectl get nodes --sort-by=.metadata.creationTimestamp
kubectl delete node $(kubectl get node |awk '/NotReady/ {print $1}')




systemctl enable docker kubelet


#Depois de resetar worker
kubeadm token create --print-join-command



### Worker
yes | kubeadm reset
export K8S_NODE_IP=
echo "KUBELET_EXTRA_ARGS=\"--node-ip=$K8S_NODE_IP\"" > /etc/sysconfig/kubelet

Reference: https://devopstales.github.io/kubernetes/k8s-change-ip/

Port-forward from windows to wsl docker instance with netsh

· Leitura de um minuto

If you want, for example, enable port 3000 served by your docker instance, follow these steps:

  1. On windows host open command prompt as administrator
  2. Type the following commands:
netsh advfirewall firewall add rule name= "Open Port 3000" dir=in action=allow protocol=TCP localport=3000

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=3000 connectaddress=localhost connectport=3000

VSCODE REST-CLIENT cheatsheet

· Leitura de um minuto
### 
# @name meuTeste
GET https://httpbin.org/get HTTP/1.1

###
# @name ipReq
GET https://api.ipify.org
?format=json

###

@server = {{meuTeste.response.headers.Server}}
@origin = {{meuTeste.response.body.$.origin}}

@allHeaders = {{meuTeste.response.body.headers}}

@ip = {{ipReq.response.body.$.ip}}

POST https://httpbin.org/post HTTP/1.1
Content-Type: application/json
X-Server: {{server}}
User-Agent: REST CLIENT VSCODE PLUGIN

{
"servidor": "{{server}}",
"origin": "{{origin}}",
"ip": "{{ip}}",
"user": "{{$processEnv USERNAME}}",
"username": "{{username}}",
"password": "{{password}}",
"all-headers": {{allHeaders}},
"documentationLink": "https://marketplace.visualstudio.com/items?itemName=humao.rest-client"

}


### Exemplo de multipartPOST {{host}}/anything HTTP/1.1
Content-Type: multipart/form-data; boundary=Boundary

--Boundary
Content-Disposition: form-data; name="text"

title of the file
--Boundary
Content-Disposition: form-data; name="text_file"; filename="trustedroot.txt"
Content-Type: text/plain

<@utf8 ./trustedroot.txt

--Boundary
Content-Disposition: form-data; name="file.txt"; filename="file.txt"
Content-Type: text/plain

<@utf8 ./file.txt
--Boundary--

Computing X-Forwarded-For header in nginx-controller

· Leitura de um minuto

Step 1 (optional)

Edit ingress-nginx-controller service:

kubectl edit -n ingress-nginx svc/ingress-nginx-controller

Change the following spec as below and save the service config:

spec: 
externalTrafficPolicy: Local

externalTrafficPolicy: Local: If set to "Local", the proxy will configure the service in a way that assumes that external load balancers will take care of balancing the service traffic between nodes, and so each node will deliver traffic only to the node-local endpoints of the service, without masquerading the client source IP. (Traffic mistakenly sent to a node with no endpoints will be dropped.)

E.g.: With this configuration, you will need to take care of the balancing properly. This step may be skipped, so you'd rather try the next step before changing this configuration.

Step 2

Edit the ingress-nginx-controller data with the following command:

kubectl edit -n ingress-nginx cm/ingress-nginx-controller

The data section must be edited like the following:

data:
compute-full-forwarded-for: "false"
use-forwarded-headers: "true"

Save the config map and restart the deployment/daemonset regarding ingress-nginx

Focus mode on linux with 'at' and 'dunst'

· Leitura de um minuto

Create this shell script on you ~/.local/bin/focusmode path with the following content:

#!/bin/sh

SIGNAL=$1

if [ -z $SIGNAL ]; then
echo "Signal must be provided: on|off"
exit -127
fi

if [ $SIGNAL == "on" ]; then
atrm $(atq -qf | cut -f1) 2> /dev/null || echo $status
notify-send --urgency=low --expire-time=1000 --category=FOCUS "Focus mode on" "Focus mode Started"
sleep 1
killall -SIGUSR1 dunst
echo "killall -SIGUSR2 dunst" | at -q f now +50 minutes
else
killall -SIGUSR2 dunst
atrm $(atq -qf | cut -f1) 2>/dev/null || echo $status
notify-send --urgency=low --expire-time=3000 --category=FOCUS "Focus mode off" "Focus mode ended"
fi
atq

Then run chmod +x ~/.local/bin/focusmode

Usage

  1. focusmode on - Will disable dunst for 50 minutes
  2. focusmode off - Will enable dunst

Requirements

  1. at package properly installed
  2. atd daemon enabled and running
  3. dunst acting as your notification daemon

See also:

  1. https://wiki.archlinux.org/title/Dunst#Disable\_dunst\_temporarily

crictl cheatsheet for k0s

· Leitura de um minuto

/etc/crictl.yaml config file:

runtime-endpoint: unix:///run/k0s/containerd.sock
image-endpoint: unix:///run/k0s/containerd.sock
timeout: 10
debug: false

Useful commands

#Pruning images
crictl rmi --prune

#listing pods by namespace 'mynamespace'
crictl pods --namespace mynamespace


#listing containers by label
crictl ps --label=mylabel=labelvalue

#Execute a command in a running container with hash 1f73f2d81bf98
crictl exec -i -t 1f73f2d81bf98 ls