From 588a69f2d0710010814e9a518ae14748caa8e333 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Mon, 23 Sep 2024 20:36:10 +0200 Subject: [PATCH] refactor(k8s): categorize commands for easier reference --- snippets/kubectl.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/snippets/kubectl.sh b/snippets/kubectl.sh index 4a79185..3daee4f 100644 --- a/snippets/kubectl.sh +++ b/snippets/kubectl.sh @@ -1,34 +1,40 @@ #!/usr/bin/env sh +# Manage namespaces kubectl create namespace 'gitlab' +# Manage secrets +kubectl apply --namespace 'gitlab' --values 'secrets.yaml' kubectl create --namespace 'gitlab' secret generic 'gitlab-runner-token' --dry-run='client' --output 'yaml' \ --from-literal='runner-registration-token=""' --from-literal='runner-token=glrt-…' -kubectl apply --namespace 'gitlab' --values 'secrets.yaml' kubectl --namespace 'gitea' create secret generic 'gitea-admin-secret' \ --from-literal 'username=gitea_admin' --from-literal "password=$(pulumi config get 'giteaAdminPassword')" +kubectl get secrets -n 'gitea' 'gitea' -o jsonpath='{.data.config_environment\.sh}' | base64 -d +kubectl get secrets -n 'gitea' 'gitea-inline-config' -o go-template='{{.data.mailer|base64decode}}' - +# Manage nodes kubectl get nodes 'fargate-ip-172-31-83-147.eu-west-1.compute.internal' -o 'yaml' | yq -y '.metadata.labels' kubectl get nodes -o jsonpath='{.items[].metadata.labels}' | yq -y +# Manage events kubectl get events -n 'monitoring' --sort-by '.metadata.creationTimestamp' +# See resources utilization # Requires the metrics server to be running in the cluster kubectl top nodes kubectl top pods - +# Create containers kubectl run --rm -it --image 'alpine' 'alpine' --command -- sh kubectl run --rm -t --image 'amazon/aws-cli:2.17.16' 'awscli' -- autoscaling describe-auto-scaling-groups kubectl -n 'kube-system' run --rm -it 'awscli' --overrides '{"spec":{"serviceAccountName":"cluster-autoscaler-aws"}}' \ --image '012345678901.dkr.ecr.eu-west-1.amazonaws.com/cache/amazon/aws-cli:2.17.16' \ autoscaling describe-auto-scaling-groups - +# Scale deployments kubectl scale deployment -n 'kube-system' 'cluster-autoscaler-aws-cluster-autoscaler' --replicas '0' - +# Add annotations kubectl annotate sc 'gp2' 'storageclass.kubernetes.io/is-default-class'='false' cat <