K8s
K8s
Knowledge, commands, parameters and everything relevant when using Kubernetes (K8s).
Simple commands
- View logs since
- Given timestamp
k logs --since-time='2023-05-14T00:00:00Z' <pod_name>
- Last n hours
k logs --since=24h <pod_name>
- Last n lines
k logs --tail=100 <pod_name>
- Given timestamp
- Get password from deployment secrets
1 2 3
k get deployments -> k describe deployment my-deployment k get secret db-password -o yaml echo <thepassword> | base64 -d
k describe secret <secret>
- Switch namespace
k config set-context --current --namespace=dev
- Show config (namespace etc.)
k config view
- Print only namespace
k config view --minify --output 'jsonpath={..namespace}'; echo
- Show deployment details
k describe deployment <deployment>
- Show information about pod (e.g. latest failures)
k descripe pod <pod>
Merge multiple config files
Automatically
Assuming:
- you have
config-one
andconfig-two
in~./kube
directory - values within files won’t conflict (override) each other
1
2
3
4
export KUBECONFIG=~/.kube/config-one:~/.kube/config-two
kubectl config view
kubectl config view --flatten
kubectl config view --flatten > common.yaml
Manually
Sometimes it’s just easier and faster to follow the template below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
apiVersion: v1
kind: Config
preferences: { }
current-context: k8s-old
contexts:
- context:
cluster: k8s-old-cluster
user: k8s-old-admin
namespace: my-old-app
name: k8s-old
- context:
cluster: k8s-new-cluster
user: k8s-new-admin
namespace: my-new-app
name: k8s-new
clusters:
- cluster:
certificate-authority-data: tomato1
server: https://1.2.3.4:1234
name: k8s-old-cluster
- cluster:
certificate-authority-data: tomato2
server: https://4.3.2.1:4321
name: k8s-new-cluster
users:
- name: k8s-old-admin
user:
client-certificate-data: tomato3
client-key-data: tomato4
- name: k8s-new-admin
user:
client-certificate-data: tomato5
client-key-data: tomato6