jinleileiking / learning-notes

Notes for my learning.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

k8s

jinleileiking opened this issue · comments

aliyun

  • docker login进不去,竟然是挂了vpn导致。。。。
  • 如果不让直接 -p 输入密码 : https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2861.
  • 拉私有镜像: kubectl create secret docker-registry regsecret --docker-server=registry.cn-zhangjiakou.aliyuncs.com --docker-username=xxxx --docker-password=xxxxxxx 注意image不要带https!
  • 私网slb : service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet". https://help.aliyun.com/document_detail/86531.htm?spm=a2c4g.11186623.0.0.2bacc00dVOK3Y7#task-1425948
  • 磁盘不够用:查是
  • /var/log/message太大,占了10g,7天2g,解决方法:修改/etc/logrotate.conf,rotate 4 -> 1 然后 systemctl restart rsyslog ---未验证
  • 镜像太多/run/containerd/io.containerd.runtime.v2.task/k8s.io cat /etc/kubernetes/kubelet-customized-args.conf https://segmentfault.com/a/1190000022163856
  • 登录k8s虚机:1. 虚机开不了外网ip,需用eip,好的办法是从另一个虚机跳过去, eip和外网ip比,eip多点维护费
  • k8s会用一个eip绑定到slb上,不知为何,收费!
  • k8s开了一个eip绑定到nat,不知道干什么用的 ??
  • rabbitmq & promtheus: https://help.aliyun.com/document_detail/161843.html?spm=a311a.7996332.0.0.2bc93080wZ9hk2
  • 拉不了私有镜像: 没有aliyun-acr-credential-helper, 安装一下就好了,猜测:老的集群建立时,点了ingress,我猜这个会自动安装这个app
  • 建不了抢占式实例:账号没权限,建了包月突发,贵一点
  • 跳板机创建:需要新建一个交换机,注意机器和交换机是绑定的,一个vpc的交换机是互通的
  • ssh到k8s机器: ssh到跳板机,copy pem到跳板机,在ssh -i pem到k8s node。
  • 跨区拉镜像:
    • 安装aliyun-acr-credential-helper
    • 改acr-configuration
    • 加regionID
- instanceId: ""
  regionId: "cn-zhangjiakou"
  • oss挂载不了
    • 增加机器到两台,解决CSI插件起不起来的问题,即oss挂载不了
    • 给k8s资源组授权oss全访问权限
  • mysql访问不了
    • 白名单加pod白名单 172.19.224.0/20
    • 建数据库后,要给账号授权
  • rabbit报vhost没权限: RAM加amqp权限

pvc

k8s to sls

{
    "inputs": [
        {
            "detail": {
                "Stderr": true,
                "IncludeLabel": {
                    "io.kubernetes.pod.namespace": "YOUR NS"
                },
                "Stdout": true
            },
            "type": "service_docker_stdout"
        }
    ]
}
  • 告警https://help.aliyun.com/document_detail/207609.html, 一个文件默认只被一个logstore,要想支持一个文件入多个logstore,需要改配置
  • logstore删了,再重启dep,有时不能重建,解决方案: 重启logtail-ds的pod.
  • 告警邮件展示自动标注: 发送内容里加一个annotations: ${annotations}
  • 监控pod启动: k8s-event库,添加* and eventId.reason: Started相关告警即可, 用自带的那个好像不好使(也许好使),但是即使好使,也无法展现podname

sls 数据加工

gitlab

job_name:
  variables:
    CI_DEBUG_TRACE: "true"
  • color : [-red-] [-green-] [-red-] [-green-]
  • 当 only:pushes, 当打tag,也会触发pushes, 如果打tag不触发pushes,要 except tag : only:pushes /n except: tags pushes = push + tags

docker

 :~/golang-image-extra$ cat /etc/docker/daemon.json
{
                    "data-root": "/data",
                                "storage-driver": "overlay2"
}
  • overlay目录清理:sudo docker system prune -a -f

docker开发srs

cicd

argocd

argo rollout

aliyun asm

k8s

  • kecm换editor: KUBE_EDITOR="nano"
  • 看node上都有神马pod : kubectl get pod -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName --all-namespaces
  • 获取headless ip : dig srv srs-origin-service.wzjinlei.svc.cluster.local SRV.NS.svc.cluster.local.
  • 强制删除: kubectl delete pods <pod> --grace-period=0 --force kubectl get pods | grep redash | awk '{print $1}' | xargs kubectl delete pod --grace-period=0 --force
  • kubectl get sc
  • pod 给pod 发信号,用于logrotate: https://kubernetes.io/docs/tasks/configure-pod-container/share-process-namespace/#configure-a-pod
  • 看 request: kubernetes/kubernetes#17512
  • kubectl get po --all-namespaces -o=jsonpath="{range .items[*]}{.metadata.namespace}:{.metadata.name}{''}{range .spec.containers[*]} {.name}:{.resources.requests.cpu}{'\n'}{end}{'\n'}{end}" | grep -e ':\d*m'
  • alias util='kubectl get nodes --no-headers | awk '\''{print $1}'\'' | xargs -I {} sh -c '\''echo {} ; kubectl describe node {} | grep Allocated -A 5 | grep -ve Event -ve Allocated -ve percent -ve -- ; echo '\'''. kubectl describe nodes
  • 给service改为loadbalancer(from argo): kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
  • k8s配置尴尬局面: https://blog.argoproj.io/the-state-of-kubernetes-configuration-management-d8b06c1205
  • 访问模式有: ReadWriteOnce 卷可以被一个节点以读写方式挂载。 ReadWriteOnce 访问模式也允许运行在同一节点上的多个 Pod 访问卷。 ReadOnlyMany 卷可以被多个节点以只读方式挂载。 ReadWriteMany 卷可以被多个节点以读写方式挂载。 ReadWriteOncePod 卷可以被单个 Pod 以读写方式挂载。 如果你想确保整个集群中只有一个 Pod 可以读取或写入该 PVC, 请使用ReadWriteOncePod 访问模式。这只支持 CSI 卷以及需要 Kubernetes 1.22 以上版本。
  • 获取客户端ip: https://www.cnblogs.com/zisefeizhu/p/13262239.html. (未实验)
  • -o yaml customize: https://www.qikqiak.com/post/boosting-kubeclt-productivity/
  • 定制指标扩缩容: https://www.qikqiak.com/post/build-k8s-app-with-custom-metrics/
  • cp文件,前面不能用绝对路径 k cp ns/pod:x.log ./a
  • cp bin进行调试: https://blog.csdn.net/StephenLu0422/article/details/78900420 patch有问题,需要自己改一下,方法是可行的
  • 笔记本打开一个pod的端口
# Change mongo-75f59d57f4-4nd6q to the name of the Pod
kubectl port-forward mongo-75f59d57f4-4nd6q 28015:27017

kustomize

helm

  • debug: helm template --debug比 helm lint方便, lint解决不了,用template看看原因
  • template用于configmap, include用于其他,好像include是用yaml的,configmap 只能用template,具体细节没研究明白
  • 遍历0123:{{range $i, $e := until (.Values.replicas | int)}} {{$i}} {{end}} 如果报float的话,用int
  • redis-helm: redis.gloabal.XXX 不好使, 要 : : :
  • upgrade无法升级pvc : spec.persistentvolumesource is immutable after creation : 要把所有的用pvc的pod停了就行 scale.
  • {{ .Release.Namespace }}
  • tips: https://www.qikqiak.com/post/helm-chart-tips-and-tricks/
  • 不删pvc: https://helm.sh/docs/howto/charts_tips_and_tricks/ (未验证)
  • comment:
{{- /*
This is a comment.
*/}}
type: frobnitz

prometheus

快速调试

发现了一个在k8s快速调试的办法,在本地build latest镜像,然后push 覆盖云上的,imagepull改为always,deletepod,新pod就会用最新的代码重启了

tips

kubectl patch svc sss -n cicd -p '{"spec": {"type": "ClusterIP"}}'

命令安装

mac安装kubectl

https://kubernetes.io/zh/docs/tasks/tools/install-kubectl-macos/

创建 ~/.kube/config 文件,将控制台的kubeconfig拷入即可

[jinleileiking:~/.kube] master(+27/-27)* ± kubectl cluster-info
Kubernetes control plane is running at xxxxxx
metrics-server is running at xxxxx/api/v1/namespaces/kube-system/services/heapster/proxy
KubeDNS is running at xxxxxxxx/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

效率提升

如果你用zsh, oh-my-zsh,

使用ohmyzsh的plugin:

我用zplug管理:改~/.vimrc 装zplug,并在vimrc添加:

zplug "plugins/kubectl", from:oh-my-zsh

然后:

[jinleileiking:~/.kube] master(+27/-27)* ± alias | grep kube | head
k=kubectl
kaf='kubectl apply -f'
kca='_kca(){ kubectl "$@" --all-namespaces;  unset -f _kca; }; _kca'
kccc='kubectl config current-context'
kcdc='kubectl config delete-context'
kcgc='kubectl config get-contexts'
kcn='kubectl config set-context --current --namespace'
kcp='kubectl cp'
kcsc='kubectl config set-context'
kcuc='kubectl config use-context'

这样就方便多了

kubens 用于换环境
kubectx 用于换namespace