Skip to content

Instantly share code, notes, and snippets.

from kubernetes import client, config
from datetime import datetime
def extract_days(pod_timestamp):
delta = datetime.now().replace(tzinfo=None) - pod_timestamp.replace(tzinfo=None)
return delta.days
@bernardoVale
bernardoVale / besteffort.sh
Created March 16, 2018 15:55
List all Pods with BestEffort
kubectl get pods --all-namespaces -o json | jq -r '.items[] | select(.status.qosClass == "BestEffort") ' | jq -r '.spec.containers[].name'
@bernardoVale
bernardoVale / cleanJob.groovy
Last active July 12, 2018 19:51
Delete all Builds && Restore to Build 1
def jobName = "folder/job/branch"
def job = Jenkins.instance.getItemByFullName(jobName)
job.getBuilds().each { it.delete() }
job.nextBuildNumber = 1
job.save()
@bernardoVale
bernardoVale / stress.sh
Created January 28, 2018 18:47
Stress test
wrk -c 20 -t 4 -d 600s https://acob-service-staging.avenuecode.com/api/v1/thirdpartyservices
@bernardoVale
bernardoVale / certificate.sh
Last active January 29, 2018 12:21
Converting certificates
# Download ca from
openssl x509 -in ~/Downloads/COMODORSAAddTrustCA.crt -inform DER -out hostname.crt.pem -outform PE
openssl x509 -inform DER -in comodo.crt -out comodo.pem -text
@bernardoVale
bernardoVale / vim.sh
Created January 26, 2018 12:37
Vim Utils
# Base64
:.!base64
# Decode
:.!base64 -D
# . = line
# % = file
# Enter mode visual, select and :!base64
@bernardoVale
bernardoVale / RECREATE.md
Created January 17, 2018 14:06
Recreate Lost PVC with unexistent PV

State, due to a bug Kubernetes lost the state of a persistent volume. The volume existed in AWS, so I've decided to recover the state.

PVC existed but with state Lost:

kubectl -n acdc-legacy get pvc
NAME                                            STATUS    VOLUME                                     CAPACITY   ACCESSMODES   STORAGECLASS   AGE
acdclegacy-staging-data-acdclegacy-postgres-0   Lost      pvc-dbd2ac08-f32e-11e7-b70d-1212ccc85de2   0                        default        10d
@bernardoVale
bernardoVale / expimp.sh
Created January 7, 2018 00:16
Export/Import Postgres
pg_dump -h 54.162.150.192 -d alpha-quester -U aquser -W > alpha.dmp
psql -h 127.0.0.1 -U aquser -W alpha-quester < alpha.dmp
@bernardoVale
bernardoVale / k8s.sh
Created January 5, 2018 12:52
Kubernetes Sheet
# Copy file from pod to my host
kubectl cp kube-system/nginx-ingress-controller-3224139886-92k85:/etc/nginx/nginx.conf nginx.conf
@bernardoVale
bernardoVale / app.py
Last active November 23, 2017 01:08
Flask mysql start
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://flask:flask@127.0.0.1/flask'
db = SQLAlchemy(app)
class Example(db.Model):
__tablename__ = 'example'