本博客持续更新…用于记录 k8s 使用过程中的很多的小技巧,也希望你能提供更多的小技巧来~
图形化 k8s 管理工具: https://github.com/lensapp/lens
我觉得可以少部署一个 dashboard,并且比官方的 dashboard 好看很多
我一开始总是 delete 一次 apply 一次,感觉很蠢,又换成调整 scle 但是还是很慢,查了之后发现原来本来就有重启的命令
kubectl rollout restart deployment nginx-dep
kubectl config view --minify --raw
当你需要使用 kubectl 操作多个集群的时候,可以使用 kubectx 切换 context,非常方便
多集群管理切换工具:https://github.com/ahmetb/kubectx
对于配置文件 configmap 的更新我真的没有找到合适的命令,直接 使用 kubectl edit 那么原来的文件是没有被更改的,会导致配置不同步。后面会尝试找找还有没有更好的方式。
#!/bin/bash
# 配置文件 ./reload-config.sh config.yaml
filename=$1
namespace=default
app=`echo $filename | cut -d . -f1`
if [ -z $app ];then
echo "filename is empty!"
exit
fi
if [ -z $namespace ];then
echo "namespace is empty!"
exit
fi
echo "start to reload [$app] configmap"
kubectl get configmap $app-config -o yaml -n $namespace
echo "---------------------start delete-----------------------------"
kubectl delete configmap $app-config -n $namespace
echo "---------------------start create-----------------------------"
kubectl create configmap $app-config --from-file=$app.yaml -n $namespace
sleep 1
kubectl get configmap $app-config -o yaml -n $namespace
configmap 修改无法自动热更新
spec:
containers:
- name: test
image: test
imagePullPolicy: Always
volumeMounts:
- name: config-volume
mountPath: /etc/test.yaml
subPath: test.yaml
volumes:
- name: config-volume
configMap:
name: test-config
spec:
containers:
- name: test
image: test
volumeMounts:
- name: config-volume
mountPath: "/conf"
volumes:
- name: config-volume
configMap:
name: test-config
items:
- key: test.json
path: test.json
spec:
containers:
- name: test
image: test
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: special-config
原来 statefulset 的访问方式是不一样的哦
https://kubernetes.io/zh/docs/concepts/services-networking/dns-pod-service/
{pod-ip}.{namespace}.pod.cluster.local //例如某pod的ip为 1.2.3.4,在命名空间default与DNS名称cluster.local将有一个域名:1-2-3-4.default.pod.cluster.local。
{pod-ip}.{namespace}.svc.cluster.local
{pod-name}.{namespace}.svc.cluster.local
{pod-name}.{subdomain}.{namespace}.svc.cluster.local // subdomain是在创建pod设定的属性,和hostname可以一起设置
{pod-name}.{service-name}.{namespace}.svc.cluster.local
可以进入到pod中查看/etc/hosts
{service-name}.{namespace}.svc.cluster.local
服务例子:
redis-service.redis.svc.cluster.local //redis-service 服务名 redis namespace