From c76108af04ecbfc4e8de0e407016379e01698e0d Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sun, 16 Jul 2023 22:40:55 +0200 Subject: [PATCH] chore: improved readibility --- ...eck a pod can connect to an external db.md | 35 ---------------- .../check pods can connect to external dbs.md | 40 +++++++++++++++++++ .../{drain a node.md => drain nodes.md} | 13 +++--- knowledge base/kubernetes/helm.md | 39 +++++++++++------- 4 files changed, 72 insertions(+), 55 deletions(-) delete mode 100644 knowledge base/kubernetes/check a pod can connect to an external db.md create mode 100644 knowledge base/kubernetes/check pods can connect to external dbs.md rename knowledge base/kubernetes/{drain a node.md => drain nodes.md} (76%) diff --git a/knowledge base/kubernetes/check a pod can connect to an external db.md b/knowledge base/kubernetes/check a pod can connect to an external db.md deleted file mode 100644 index 20fa22e..0000000 --- a/knowledge base/kubernetes/check a pod can connect to an external db.md +++ /dev/null @@ -1,35 +0,0 @@ -# Check a Pod can connect to an external DB - -## Table of contents - -1. [TL;DR](#tldr) -1. [Further readings](#further-readings) - -## TL;DR - -```sh -# access a test container -kubectl run --generator=run-pod/v1 --limits 'cpu=200m,memory=512Mi' --requests 'cpu=200m,memory=512Mi' --image alpine ${USER}-mysql-test -it -- sh - -# install programs -apk --no-cache add mysql-client netcat-openbsd - -# test plain connectivity -nc -vz -w3 10.0.2.15 3306 - -# test the client can connect -mysql --host 10.0.2.15 --port 3306 --user root -``` - -## Further readings - -- [Kubernetes] -- [`kubectl`][kubectl] - - - - -[kubectl]: kubectl.md -[kubernetes]: README.md diff --git a/knowledge base/kubernetes/check pods can connect to external dbs.md b/knowledge base/kubernetes/check pods can connect to external dbs.md new file mode 100644 index 0000000..2b9cdad --- /dev/null +++ b/knowledge base/kubernetes/check pods can connect to external dbs.md @@ -0,0 +1,40 @@ +# Check Pods can connect to external DBs + +## Table of contents + +1. [TL;DR](#tldr) +1. [Further readings](#further-readings) + +## TL;DR + +1. Get a shell on a test container. + ```sh + kubectl run --generator='run-pod/v1' --image 'alpine' -it --rm \ + --limits 'cpu=200m,memory=512Mi' --requests 'cpu=200m,memory=512Mi' \ + ${USER}-mysql-test -- sh + ``` +1. Install the utility applications needed for the tests. + ```sh + apk --no-cache add 'mysql-client' 'netcat-openbsd'' + ``` +1. Test basic connectivity to the external service. + ```sh + nc -vz -w3 '10.0.2.15' '3306' + ``` +1. Test application connectivity. + ```sh + mysql --host '10.0.2.15' --port '3306' --user 'root' + ``` + +## Further readings + +- [Kubernetes] +- [`kubectl`][kubectl] + + + + +[kubectl]: kubectl.md +[kubernetes]: README.md diff --git a/knowledge base/kubernetes/drain a node.md b/knowledge base/kubernetes/drain nodes.md similarity index 76% rename from knowledge base/kubernetes/drain a node.md rename to knowledge base/kubernetes/drain nodes.md index 2caf36d..36345ce 100644 --- a/knowledge base/kubernetes/drain a node.md +++ b/knowledge base/kubernetes/drain nodes.md @@ -1,4 +1,4 @@ -# Drain a K8S cluster node +# Drain nodes in K8S clusters ## Table of contents @@ -8,14 +8,16 @@ ## TL;DR -1. mark the node as unschedulable (_cordon_): +1. **Cordon** the Nodes.
+ This marks each Node as _unschedulable_ and prevents new Pods to start on them. ```sh $ kubectl cordon 'kworker-rj2' node/kworker-rj2 cordoned ``` -1. remove pods running on the node: +1. **Drain** the nodes.
+ This _evicts_ Pods already running on the Nodes. ```sh $ kubectl drain 'kworker-rj2' --grace-period=300 --ignore-daemonsets=true @@ -26,8 +28,9 @@ node/kworker-rj2 evicted ``` -1. do to the node what you need to do -1. make the node available again: +1. Do to the Nodes what you need to do. +1. **Uncordon** the Nodes. + This makes them available for scheduling again. ```sh $ kubectl uncordon 'kworker-rj2' diff --git a/knowledge base/kubernetes/helm.md b/knowledge base/kubernetes/helm.md index 5f780e8..1ee6026 100644 --- a/knowledge base/kubernetes/helm.md +++ b/knowledge base/kubernetes/helm.md @@ -16,26 +16,34 @@ helm plugin list helm plugin ls # Install new plugins. -helm plugin add https://github.com/author/plugin -helm plugin install path/to/plugin +helm plugin add 'https://github.com/author/plugin' +helm plugin install 'path/to/plugin' # Update installed plugins. -helm plugin update plugin-name -helm plugin up plugin-name +helm plugin update 'plugin_name' +helm plugin up 'plugin_name' # Uninstall plugins. -helm plugin rm plugin-name -helm plugin remove plugin-name -helm plugin uninstall plugin-name +helm plugin rm 'plugin_name' +helm plugin remove 'plugin_name' +helm plugin uninstall 'plugin_name' -# Manage repositories. + +# List added repositories. helm repo list + +# Add repositories. helm repo add 'grafana' 'https://grafana.github.io/helm-charts' helm repo add 'ingress-nginx' 'https://kubernetes.github.io/ingress-nginx' + +# Update repositories. helm repo update helm repo update 'keda' + +# Remove repositories. helm repo remove 'prometheus' + # Search for specific charts helm search hub --max-col-width '100' 'ingress-nginx' helm search repo 'grafana' @@ -50,6 +58,7 @@ helm pull 'ingress-nginx/ingress-nginx' --version '4.0.6' \ # Get the default values of specific charts. helm inspect values 'gitlab/gitlab' + # Install releases helm install 'my-gitlab' 'gitlab/gitlab' helm upgrade --install 'my-gitlab' 'gitlab/gitlab' @@ -61,13 +70,13 @@ helm upgrade --install 'keda' 'keda' \ --repo 'https://kedacore.github.io/charts' \ --namespace 'keda' --create-namespace -# Upgrade deployed releases +# Upgrade deployed releases. helm upgrade --install 'my-wordpress' 'wordpress' -helm upgrade --values values.yaml 'my-wordpress' 'wordpress' +helm upgrade --values 'values.yaml' 'my-wordpress' 'wordpress' helm upgrade --namespace 'gitlab' --values 'values.yaml' 'gitlab gitlab/gitlab' --dry-run helm upgrade --atomic --create-namespace --namespace 'gitlab' --timeout 0 --values 'values.yaml' 'gitlab' 'gitlab/gitlab' --debug -# Inspect deployed releases' manifest +# Inspect deployed releases' manifests. helm get manifest 'wordpress' ``` @@ -82,12 +91,12 @@ To achieve this: ```yaml annotations: meta.helm.sh/release-name: app-release-name - meta.helm.sh/release-namespace: app-deploy-namespace-name + meta.helm.sh/release-namespace: app-deployment-namespace-name labels: app.kubernetes.io/managed-by: Helm ``` - with `app-release-name` being the release name used to deploy the helm chart and `app-deploy-namespace-name` being the deployment namespace + with `app-release-name` being the release name used to deploy the helm chart and `app-deployment-namespace-name` being the deployment namespace. ```sh kubectl annotate "$KIND" "$NAME" "meta.helm.sh/release-name=${RELEASE_NAME}" @@ -95,11 +104,11 @@ To achieve this: kubectl label "$KIND" "$NAME" "app.kubernetes.io/managed-by=Helm" ``` -1. add now the existing resources' manifests to the chart +1. now, add the existing resources' manifests to the chart 1. execute a chart upgrade: ```sh - helm upgrade + helm upgrade 'app-release-name' ``` ## Further readings