cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: restore
namespace: monitoring
spec:
securityContext:
fsGroup: 1000 # GID del usuario del container tf-infra
containers:
- name: restore
image: ubuntu:latest
imagePullPolicy: IfNotPresent
command: [ "/bin/sh", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
volumeMounts:
- name: loki
mountPath: /data/loki
- name: prometheus
mountPath: /data/prometheus
restartPolicy: Never
volumes:
- name: loki
persistentVolumeClaim:
claimName: storage-loki-stack-0
- name: prometheus
persistentVolumeClaim:
claimName: prometheus-kube-prometheus-stack-prometheus-db-prometheus-kube-prometheus-stack-prometheus-0
EOF
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
# block not whitelilsted ips returns a 403 error
nginx.ingress.kubernetes.io/whitelist-source-range: 1.1.1.1/32,2.2.2.2/32
nginx.ingress.kubernetes.io/server-snippet: |
error_page 403 = @errorpages; # catch the error
location @errorpages {
return 503 "We are on maintenance mode.
Please come back later.";
}
helm repo add cert-manager https://charts.jetstack.io
helm repo update
helm search repo <repo_name>
helm pull [chart URL | repo/chartname] [...] [flags]
# evaluar el values.yaml en el template
helm template ./chart
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
namespace: devops
labels:
app: ubuntu
spec:
containers:
- image: ubuntu:latest
imagePullPolicy: Always
name: ubuntu
command: [ "/bin/sh", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: NodeGroup
operator: In
values:
- system
tolerations:
- key: dedicated
operator: Equal
value: system
effect: NoSchedule
apiVersion: apps/v1 kind: Deployment metadata: name: ubuntu-geko namespace: devops labels: app: ubuntu spec: replicas: 1 selector: matchLabels: app: ubuntu template: metadata: labels: app: ubuntu spec: containers: - name: ubuntu image: ubuntu:latest imagePullPolicy: Always command: [ "/bin/sh", "-c", "--" ] args: [ "while true; do sleep 30; done;" ]
#!/bin/bash
# docker run -d -p 3001:3001 --name monit_scout -v scout_pro:/app/data louislam/uptime-kuma:1
# docker start monit_scout
# De 1.30 a 1.31
# 1. aplicar upgrade desde consola
# 2. aplicar upgrade desde terraform con environment 1.31
# 1. revisar versiones de plugins
# 3. Rotar nodos
# Cordon nodes
REMOVING_VERSION="1.30"
NODOS=$(kubectl get node | grep ${REMOVING_VERSION} | awk '{print $1}')
# Cordon
for nodo in ${NODOS}
do
echo "Cordon ${nodo}"
kubectl cordon ${nodo}
kubectl get node ${nodo}
done
for NODE in ${NODOS}
do
kubectl get node $NODE
EC2_ID=$(kubectl get node ${NODE} -o json | jq -r '.metadata.annotations["csi.volume.kubernetes.io/nodeid"] | fromjson | .["ebs.csi.aws.com"]')
read -p "Press enter to continue with next Node"
echo "Drain $NODE"
kubectl drain $NODE --ignore-daemonsets --delete-emptydir-data --force
echo "Drain DONE! ..."
echo "-------------------------"
echo "Still running PODs"
kubectl describe node ${NODE} | awk '/Non-terminated Pods:/ {flag=1; next} /Allocated resources:/ {flag=0} flag'
echo
echo
read -p "Remove from K8S node: ${NODE}? " yn
if [[ $y/n =~ ^[Yy]$ ]]; then
echo "delete node $NODE"
kubectl delete node $NODE
read -p "Remove Node: ${NODE} EC2_id: ${EC2_ID}? " yn
if [[ $y/n =~ ^[Yy]$ ]]; then
# remove EC2 and auto adjust the ASG, so no new node is deployed
echo "autoscaling terminate-instance-in-auto-scaling-group"
# aws autoscaling terminate-instance-in-auto-scaling-group --instance-id ${EC2_ID} --should-decrement-desired-capacity
aws autoscaling terminate-instance-in-auto-scaling-group --instance-id ${EC2_ID} --no-should-decrement-desired-capacity
fi
fi
done
# NODE=""
# EC2_ID=$(kubectl get node ${NODE} -o json | jq -r '.metadata.annotations["csi.volume.kubernetes.io/nodeid"] | fromjson | .["ebs.csi.aws.com"]')
# kubectl drain $NODE --ignore-daemonsets --delete-emptydir-data --force
# kubectl describe node ${NODE} | awk '/Non-terminated Pods:/ {flag=1; next} /Allocated resources:/ {flag=0} flag'
# kubectl delete node $NODE
# aws autoscaling terminate-instance-in-auto-scaling-group --instance-id ${EC2_ID} --no-should-decrement-desired-capacity
k apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: ubuntu-infinite
spec:
replicas: 1
selector:
matchLabels:
app: ubuntu-infinite
template:
metadata:
labels:
app: ubuntu-infinite
spec:
containers:
- name: ubuntu
image: ubuntu:latest
command:
- /bin/bash
- -c
- |
while true; do
sleep 3600
done
EOF