查看“K8s基础”的源代码
←
K8s基础
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
=base= [[K8s应用#2022]] [[Rancher基础]] #使用glusterfs做存储,不懂glusterfs的请参考其他文章 ==命名空间 == [https://www.jianshu.com/p/66a963a646f7 k8s实战示例1:创建命名空间和简单pod] == label== === 给节点打标签label=== <pre> root@ubuntu-200470-1:~/pod# kubectl get node NAME STATUS ROLES AGE VERSION master Ready control-plane 22d v1.24.10 work1 Ready <none> 22d v1.24.10 work2 Ready <none> 22d v1.24.10 #给节点1 work1打上 nodename=node01 root@ubuntu-200470-1:~/pod# kubectl label nodes work1 nodename=node01 node/work1 labeled #查看效果 root@ubuntu-200470-1:~/pod# kubectl get node --show-labels=true NAME STATUS ROLES AGE VERSION LABELS master Ready control-plane 22d v1.24.10 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers= work1 Ready <none> 22d v1.24.10 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=work1,kubernetes.io/os=linux,nodename=node01 work2 Ready <none> 22d v1.24.10 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=work2,kubernetes.io/os=linux #使用 例如在dp apiVersion: apps/v1 kind: Deployment metadata: name: dep-nginx-sel-node spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx ver: beta spec: containers: - name: nginx image: nginx:1.25.2-alpine imagePullPolicy: IfNotPresent nodeSelector: nodename: node01 </pre> === label svc=== <pre> oot@ubuntu-200470-1:~/oct19# kubectl get svc nginx --show-labels NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE LABELS nginx ClusterIP None <none> 80/TCP 6h15m app=nginxlabelstest root@ubuntu-200470-1:~/oct19# kubectl label svc nginx version=1 service/nginx labeled root@ubuntu-200470-1:~/oct19# kubectl get svc nginx --show-labels NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE LABELS nginx ClusterIP None <none> 80/TCP 6h15m app=nginxlabelstest,version=1 root@ubuntu-200470-1:~/oct19# kubectl label svc nginx version- service/nginx unlabeled root@ubuntu-200470-1:~/oct19# kubectl get svc nginx --show-labels NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE LABELS nginx ClusterIP None <none> 80/TCP 6h16m app=nginxlabelstest root@ubuntu-200470-1:~/oct19# </pre> == controllers 控制器== ===[[控制器DaemonSet]]=== ===[[控制器CronJob]]=== =[[Helm3]]= =k8s-imagePullPolicy拉取策略= imagePullPolicy: Always 总是拉取 pull 以前好像是这个默认值 imagePullPolicy: IfNotPresent 默认值,本地有则使用本地镜像,不拉取 imagePullPolicy: Never 只使用本地镜像,从不拉取 =k8s 进入pod shell= <pre> kubectl get pods #查看所有正在运行的pod NAME READY STATUS RESTARTS AGE nginx-56b8c64cb4-t97vb 1/1 Running 3 1d kubectl exec -it nginx-56b8c64cb4-t97vb -- /bin/bash #假如当前pod只有一个容器,运行以下命令即可 root@nginx-56b8c64cb4-t97vb:/# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 14:45 ? 00:00:00 nginx: master process nginx -g daemon off; 假如一个pod里有多个容器,用--container or -c 参数。例如:假如这里有个Pod名为my-pod,这个Pod有两个容器,分别名为main-app 和 helper-app,下面的命令将打开到main-app的shell的容器里。 kubectl exec -it my-pod --container main-app -- /bin/bash </pre> [https://www.cnblogs.com/to-here/p/13050760.html k8s不进入pod,直接通过shell在pod里执行命令 ] [https://blog.51cto.com/u_12708233/2375897 k8s使用shell进入容器被拒绝连接] = k8s删除pod = <pre> 1、先删除pod2、再删除对应的deployment否则只是删除pod是不管用的,还会看到pod,因为deployment.yaml文件中定义了副本数量 实例如下: 删除pod [root@test2 ~]# kubectl get pod -n jenkins NAME READY STATUS RESTARTS AGE jenkins2-8698b5449c-grbdm 1/1 Running 0 8s [root@test2 ~]# kubectl delete pod jenkins2-8698b5449c-grbdm -n jenkins pod "jenkins2-8698b5449c-grbdm" deleted 查看pod仍然存储 [root@test2 ~]# kubectl get pod -n jenkins NAME READY STATUS RESTARTS AGE jenkins2-8698b5449c-dbqqb 1/1 Running 0 8s [root@test2 ~]# 删除deployment [root@test2 ~]# kubectl get deployment -n jenkins NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE jenkins2 1 1 1 1 17h [root@test2 ~]# kubectl delete deployment jenkins2 -n jenkins 再次查看pod消失 deployment.extensions "jenkins2" deleted [root@test2 ~]# kubectl get deployment -n jenkins No resources found. [root@test2 ~]# [root@test2 ~]# kubectl get pod -n jenkins No resources found. </pre> [ k8s中正确删除一个pod k8s中正确删除一个pod ] =常见组件安装= == [[安装Metrics server]]== =[[hpa]]= =coredns状态为ImagePullBackOff问题= <pre> kubectl get pods --all-namespaces kube-system coredns-7f6cbbb7b8-knhl8 0/1 ImagePullBackOff 0 24h kube-system coredns-7f6cbbb7b8-lt4k5 0/1 ImagePullBackOff 0 24h 解决办法: 确定pod所使用的镜像 kubectl get pods coredns-7f6cbbb7b8-knhl8 -n kube-system -o yaml | grep image image: registry.aliyuncs.com/google_containers/coredns:v1.8.4 imagePullPolicy: IfNotPresent - image: registry.aliyuncs.com/google_containers/coredns:v1.8.4 imageID: "" message: Back-off pulling image "registry.aliyuncs.com/google_containers/coredns:v1.8.4" root@k8s-master:~# docker pull registry.aliyuncs.com/google_containers/coredns:v1.8.4 Error response from daemon: manifest for registry.aliyuncs.com/google_containers/coredns:v1.8.4 not found: manifest unknown: manifest unknown 拉个latest 再别名 docker pull registry.aliyuncs.com/google_containers/coredns root@k8s-master:~# docker images | grep coredns registry.aliyuncs.com/google_containers/coredns latest 8d147537fb7d 3 months ago 47.6MB 强制 改一下 tag root@k8s-master:~# docker tag 8d147537fb7d registry.aliyuncs.com/google_containers/coredns:v1.8.4 root@k8s-master:~# kubectl get pods --all-namespaces | grep coredns kube-system coredns-7f6cbbb7b8-knhl8 1/1 Running 0 24h kube-system coredns-7f6cbbb7b8-lt4k5 1/1 Running 0 24h root@k8s-master:~# root@k8s-master:~# kubectl get all -n kube-system NAME READY STATUS RESTARTS AGE pod/coredns-7f6cbbb7b8-knhl8 0/1 ImagePullBackOff 0 24h pod/coredns-7f6cbbb7b8-lt4k5 0/1 ImagePullBackOff 0 24h docker pull registry.aliyuncs.com/google_containers/coredns </pre> [https://blog.csdn.net/weifangwei100/article/details/118940876 coredns状态为ImagePullBackOff问题] [https://blog.csdn.net/hbuxiaofei/article/details/117632562 k8s解决coredns 的ImagePullBackOff 和ErrImagePull 问题] https://stackoverflow.com/questions/53559291/kubernetes-coredns-in-crashloopbackoff [https://blog.csdn.net/qq_24046745/article/details/93988920 Kubernetes CoreDNS 状态是 CrashLoopBackOff 解决思路] =CrashLoopBackOff的解决方法= [https://blog.csdn.net/u012803274/article/details/114155844 记录一次修复k8s pod长时间处于CrashLoopBackOff状态问题] [https://www.jianshu.com/p/bcc05427990d k8s启动Pod遇到CrashLoopBackOff的解决方法] =k8s常见问题= ==pod无故重启 == OOM [https://segmentfault.com/a/1190000039984292 运维攻坚之kubernetes pod无故重启问题排查] [https://www.cnblogs.com/chopper-poet/p/15328054.html 记一次k8s pod频繁重启的优化之旅] [https://blog.csdn.net/hongxiaolu/article/details/113711718 POD 中容器异常重启原因定位] =see also= [https://it.baiked.com/kubernetes/2833.html 几款k8s快速部署的开源项目对比] [https://blog.csdn.net/kunyus/article/details/88840999 kuernetes 修改pod时区的方法] =docker基础知识= [https://www.cnblogs.com/yinzhengjie/p/12183066.html Linux的namespace和cgroups简介] [[category:k8s]]
返回至
K8s基础
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
我的导航
关于我
shell
python
ops
linuxchina.net
blog.linuxchina
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息