8000 teymurgahramanov’s gists · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Instantly share code, notes, and snippets.

View teymurgahramanov's full-sized avatar
🚀
Harder, Better, Faster, Stronger

Teymur Gahramanov teymurgahramanov

🚀
Harder, Better, Faster, Stronger
View GitHub Profile
@teymurgahramanov
teymurgahramanov / README.md
Last active December 6, 2023 07:49
Helm named templates to ensure the same metadata across all manifests in the chart.

With these named templates you can ensure the same metadata (resource name, namespace, labels, annotations) across all templates in your Helm chart. It is also can be used inside range loops.

Examples:

  1. In ingress.yaml there is an example of using common.metadata template without extra argument.
  2. In vault-secrets.yaml there is a more complex example of using common.metadata, and resource.name templates inside loop by passing $key for generating VaultAuth and VaultStaticSecret for each key name in the values file.
@teymurgahramanov
teymurgahramanov / get-kube-volumes.sh
Last active September 4, 2023 14:20
Get the list of GlusterFS volumes, PVCs, and list of Helm Chart releases that use them
for pv in $(kubectl get pv -o custom-columns="NAME:.metadata.name" --no-headers); do
GLUSTERFS_PATH=$(kubectl get pv -A $pv -o yaml | yq .spec.glusterfs.path)
PVC_NAME=$(kubectl get pv $pv -o yaml | yq .spec.claimRef.name)
USED_BY=()
for chart in $(kubectl get deployments --all-namespaces -o=json | \
jq --arg pvc "$PVC_NAME" -r '.items[] | select(.spec.template.spec.volumes[]?.persistentVolumeClaim.claimName == $pvc) | .metadata.annotations."meta.helm.sh/release-name"'); do
USED_BY+=($chart)
done
echo "$GLUSTERFS_PATH,$PVC_NAME,${USED_BY[*]}"
done
@teymurgahramanov
teymurgahramanov / merge-kubectl-config.sh
Last active September 10, 2023 10:31
Merge Multiple Kubernetes kubectl config files into a single
# Make a copy of your kubeconfig file:
cp ~/.kube/config ~/.kube/config-backup
# Create files with your contexts, like ~/.kube/cluster-1 ~/.kube/cluster-2 ... And create KUBECONFIG env variable:
export KUBECONFIG=~/.kube/:$(find ~/.kube -maxdepth 1 -type f | tr '\n' ':')
# Create new ~/.kube/config
kubectl config view --flatten > ~/.kube/config
# Verify
@teymurgahramanov
teymurgahramanov / README.md
Last active February 14, 2024 06:46
Prometheus alerts based on resource labels via Alertmanager

Prometheus alerts based on resource labels via Alertmanager

Assume that you have several development teams which are work on the same Kubernetes cluster and each team need to get alerts only related to their projects. For example, team "A" should only get alerts if there are any unhealthy pods with labels team: A and app: app1 or app: app2

Requirements:

  • Appropriate labels on your pods
  • kube-state-metrics (tested with 2.4.2 version) with argument --metric-labels-allowlist=pods=[*]
  • Prometheus job for pods
  • Prometheus rule which will join pod labels from kube_pod_labels to metric e.g.
kubectl run troubleshoot-curl --image=curlimages/curl --rm -it --restart=Never -- curl -XPOST http://alertmanager.infra:9093/api/v1/alerts -d '[{"status": "firing","labels": {"alertname": "Test alert","env":"prod","service": "dummy","severity": "critical","instance": "1"},"annotations": {"summary": "This is a test alert.","description": "This is a description for test alert."},"generatorURL": "http://prometheus.example.com"}]'
@teymurgahramanov
teymurgahramanov / README.md
Last active November 18, 2022 13:40
Solution of empty database problem after gitlab-ctl pg-upgrade

Solution of empty database problem after gitlab-ctl pg-upgrade

Сase:

Unable to upgrade GitLab 13.X.X (Linux package) to 14.X.X because it does not support PostgreSQL version less than 12 (Current 11). Tried to upgrade PostgreSQL using gitlab-ctl pg-upgrade -V 12 as described in Upgrade packaged PostgreSQL server.

Expected behavior

This updates PostgreSQL to the default shipped version during package upgrades, unless specifically opted out.

Current behavior

gitlab-ctl pg-upgrade -V 12 finishes successfully but ends with an empty database and GitLab acts as if a fresh install.

@teymurgahramanov
teymurgahramanov / README.md
Last active October 25, 2022 19:47
Dynamic HTML Table with Jinja2

Dynamic HTML Table with Jinja2

The Jinja2 template snippet for generating HTML table, based on data retrieved from the database.

In this example, assumed that we have two lists:

  • db_data_columns for columns
  • db_data_rows for rows
@teymurgahramanov
teymurgahramanov / README.md
Last active October 18, 2022 12:29
Kubernetes dynamic secret for Image Registry using Helm and Gitlab

Kubernetes dynamic secret for Image Registry using Helm and Gitlab

Instead of manually creating secret for pulling images from Image Registry we can generate it using variables during pipeline.

For example assume that:

  • your template for secret is as example-helm-secret-template.yaml
  • you have $DOCKER_USER $DOCKER_PASSWORD variables.
  • you are using Gitlab Container Registry

Just add this override to helm install command:

@teymurgahramanov
teymurgahramanov / README.md
Last active October 14, 2022 12:06
Ansible change password of current user on fly

Ansible change password of current user on fly

You also can change other connection parameters in this way during playbook execution.

@teymurgahramanov
teymurgahramanov / README.md
Last active October 14, 2022 11:52
Ansible handler to reload and check systemd's service status

Ansible handler to reload and check systemd's service status

0