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
- https://help.aliyun.com/document_detail/134722.html
- pv的 aksk是 oss的
- 按照官网方法2, 要加label,文档竟然是错误的,没加。。。。
k8s to sls
- https://help.aliyun.com/document_detail/87540.html?spm=5176.smartservice_service_robot-chat.help.dexternal.6c674b0dRyuKQp
- project不要新建,用建立k8s自带的,要不然找不到机器组
- 示例配置(废弃,新的直接搞yaml就可以,yaml的logstore会自动建立,更少的控制台操作)
{
"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 数据加工
- 数据加工建立后,报错,python脚本说没有你要的logstore: 自己建一个。。。。。
- json展开: https://help.aliyun.com/document_detail/125488.html#section-o7x-7rl-2qh
- srs的log带了颜色,数据加工不能简单排除,最后用文件解决这个问题,但srs不会自动建立目录,需要注意
gitlab
- runner 显示$是正常的,怕泄漏
- docker 里build不了docker: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/1986
- docker login 不行,要stdin: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2861
- docker build 不成功: srs 要
-f ./trunk/Dockerfile .
- docker push 不上去:runner挂了代理。。。。
- srs :
sudo docker build-t rdqa/zzzzzz:test -f ./trunk/Dockerfile .
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
docker push registry.cn-zhangjiakou.aliyuncs.com/xxxx/zzzzz:test
- 引用 issue https://docs.gitlab.com/ee/user/project/issues/crosslinking_issues.html
- gitlabci使用私有仓库做基础镜像:https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#determine-your-docker_auth_config-data
standard_init_linux.go:211: exec user process caused "exec format error"
在m1编的镜像 linux用不了 : https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/4558- 在job前加.可以跳过阶段
- gitlab改基础镜像的entry:
image:entrypoint
- gitlab覆盖率需要在cicd配置
total:\s+\(statements\)\s+(\d+.\d+\%)
- CI_COMMIT_REF_NAME : 新代码的分支名
To push a commit without triggering a pipeline, add [ci skip] or [skip ci], using any capitalization, to your commit message.
- gitlab runner取镜像,sha变了, latest不会同步,解决:用tag。。。
- centos瘦身:
yum install a && yum install b 改为 install a b && yum clean all && rm -rf /var/cache/yum
- 不管downstream 的状态直接success: 得加
strategy: depend
- docker prune 只清没tag的, 有tag得 docker image rm
No permissions to trigger downstream pipeline
提升commiter的权限就好了,不知道为啥- debug ci job:
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
- docker login不要sudo ....
- 没办法给一个启动的docker expose端口 : https://stackoverflow.com/questions/19897743/exposing-a-port-on-a-live-docker-container.
-p 8935:1935
docker run -v /xxxxxxxxx/trunk:/srstrunk --name srs3 -P -dit srsdev /bin/bash
- 起个centos:
docker run -it centos
- 有些镜像设置了启动命令不是shell,你要进sh,怎么办?
docker run --entrypoint '/bin/sh' -it k8s.gcr.io/kustomize/kustomize:v3.8.7
- docker pull超出dockerhub次数: https://cloud.tencent.com/developer/article/1701933(未验证)
- alpine/git没有bash, docker:latest没有git, bash+git就乖乖centos+git把
- 地方不够,dockerbuild: 重启不了docker的话,删了重装。。。。
:~/golang-image-extra$ cat /etc/docker/daemon.json
{
"data-root": "/data",
"storage-driver": "overlay2"
}
- overlay目录清理:
sudo docker system prune -a -f
docker开发srs
- entrypoint 和cmd 如果都有,那cmd就是entrypoint的参数。。。 https://www.cnblogs.com/sparkdev/p/8461576.html
- 没有cmd的镜像也可以跑起来,注意mount的话, /xxxx:/xxxx 都要是绝对目录,否则不行! https://stackoverflow.com/questions/18878216/docker-how-to-live-sync-host-folder-with-container-folder
- dockerfile 的expose 是给 docker直接打开的端口, 宿主机无法访问,所以得 -P 或 -p
cicd
- argo :https://zhuanlan.zhihu.com/p/181692322
- https://github.com/spinnaker/spinnaker
- weave
- tekton
- jenkins X
argocd
- 先在gitlab建立自己的token, 然后argo 连接的时候, username:就是gitlab你的username, token就是刚才的token,skip version ssl
- argo的git url是取里面的yaml进行部署,不是sourcecode,如果要递归,需要点一下recursive
- sync不成功的话,ns没建,他不会自己建ns
- https://medium.com/@andrew.kaczynski/gitops-in-kubernetes-argo-cd-and-gitlab-ci-cd-5828c8eb34d6 比较好
- 应该会自动忽略.的部署: argoproj/argo-cd#2638
- argocd ns删除不掉:
kubectl get Application -n argocd
然后delete,但是不行,改一下finilizer:finalizer: []
. done. - argocd用helm 看不到,是因为:argo执行
helm template . <options> | kubectl apply -f -
- 覆盖values.yaml : https://argo-cd.readthedocs.io/en/stable/user-guide/helm/#helm-parameters (未成功)
argo rollout
aliyun asm
- 我的ack版本不支持asm,等了一周后支持了,然后开始调试
- rollout一点反应也没有,发现是argo rollout没安装。。。。。
- 安装后提示 vs找不到,这是因为asm 数据平面要找控制平面,需要打通:https://help.aliyun.com/document_detail/336919.htm?spm=5176.13895322.help.dexternal.43de5fcfhw5OAi
- 按照文档安装后,提示ram没权限,我给了个AliyunASMFullAccess 好使了,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
- docker的kustomize镜像基于alpine,起了他的bin,所以不能做基础镜像,用centos7 + curl
- 使用简介:https://blog.stack-labs.com/code/kustomize-101/
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
- template 好像不能渲染里面的if,巨坑,折腾一下午,得用include xxx .
- helm 因为 超时导致failed,然后upgrade不成功, helm history 可以看原因,解决:https://jacky-jiang.medium.com/how-to-fix-helm-upgrade-error-has-no-deployed-releases-mystery-3dd67b2eb126
prometheus
- https://www.qikqiak.com/k8s-book/docs/58.Prometheus%20Operator.html
- https://juejin.cn/post/6844903908251451406
快速调试
发现了一个在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