# Kubernetes

## Kubernetes

### Tools

#### [Kind](https://github.com/kubernetes-sigs/kind)

#### [kubectx/kubens](https://github.com/ahmetb/kubectx)

Super useful for easily switching contexts and namespaces

#### [Stern](https://github.com/wercker/stern)

Great for live tailing logs from multiple pods/containers

#### [kube-ps1](https://github.com/jonmosco/kube-ps1)

Shows some nice Kubernetes output in the CLI

#### [keda](https://keda.sh/)

#### [chart-testing](https://github.com/helm/chart-testing)

The `ct` command is great for testing Helm charts

### Commands

**Get pods**

```bash
kubectl get po
```

**Create Service Account**

**ClusterRoleBinding**

**Rollout Restart**

`kubectl rollout restart -n $namespace deployment/$deployment-name`

**Running a one-off command against a pod**

The below runs `env` within the pod without having the directly exec into it

```
kubectl exec -it my-pod-name -- env
```

**Tail logs**

Use stern for this!

**Init Containers**

To view logs from the init container, use the `-c` flag

```
kubectl logs <pod-name> -c <init-container>
```

### Resources

#### [External Secrets](https://github.com/external-secrets/kubernetes-external-secrets)

Used to create `Secret` resources without needing to store credentials in source control!

AWS system manager (Parameter )

**Basic Setup**

```yaml
apiVersion: "kubernetes-client.io/v1"
kind: ExternalSecret
metadata:
  name: hello-service
spec:
  backendType: systemManager
  data:
    - name: password
      key: /hello-service/password
```

### Namespaces

#### Deleting namespaces

Namespaces can often get stuck in a `Terminating` process despite being completely empty

To fully delete the namespace, run the following

```bash
NAMESPACE=linkerd
kubectl get namespace $NAMESPACE -o json > $NAMESPACE.json
sed -i -e 's/"kubernetes"//' $NAMESPACE.json
kubectl replace --raw "/api/v1/namespaces/$NAMESPACE/finalize" -f ./$NAMESPACE.json
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.harrison.kim/notes/kubernetes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
