Kubernetes-FAQ

Kubernetes-FAQ

Kubernetes-FAQ

incompatible CNI versions; config is \"1.0.0\", plugin supports [\"0.1.0\" \"0.2.0\" \"0.3.0\" \"0.3.1\" \"0.4.0\"]"

原因是cni的配置冲突了/etc/cni/里面的文件检查下版本,升级版本到一致

The docker driver should not be used with root privileges

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
sudo -iu liuliancao
sudo usermod -aG docker $USER && newgrp docker
liuliancao@master0:~$ minikube start --driver=docker --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
😄  minikube v1.28.0 on Debian 11.5 (kvm/amd64)
✨  Using the docker driver based on user configuration

🧯  The requested memory allocation of 2200MiB does not leave room for system overhead (total system memory: 2876MiB). You may face stability issues.
💡  Suggestion: Start minikube with less memory allocated: 'minikube start --memory=2200mb'

📌  Using Docker driver with root privileges
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...

yaml记不住怎么办

多用官方文档,搜索关键词

比如搜索pod,就能看到官方的示例pod

kubectl get pod -o pod.yaml

利用get导出yaml查看

利用kubectl explain

多用kubectl explain 相当于命令行文档

 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
root@master1:~/study/pod# kubectl explain pod
KIND:     Pod
VERSION:  v1

DESCRIPTION:
     Pod is a collection of containers that can run on a host. This resource is
     created by clients and scheduled onto hosts.

FIELDS:
   apiVersion	<string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

   kind	<string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

   metadata	<Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

   spec	<Object>
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

   status	<Object>
     Most recently observed status of the pod. This data may not be up to date.
     Populated by the system. Read-only. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

通过第一次explain我们知道pod定义里面可以写apiVersion, kind, metadata, spec, status(readonly)

我们继续explain

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
root@master1:~/study/pod# kubectl explain pod.kind
KIND:     Pod
VERSION:  v1

FIELD:    kind <string>

DESCRIPTION:
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

我们看到对应链接,查看即可,这里其实已经告诉我们kind填Pod

报错Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "kubernetes")

解决

1
2
3
4
root@master1:~# mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
cp: overwrite '/root/.kube/config'? yes

Opening a shell when a Pod has more than one container

1
kubectl exec -i -t my-pod --container main-app -- /bin/bash

–container xxx

Pod里面没有telnet怎么测试端口连通性

如果有python可以用python telnetlib

1
2
import telnetlib
telnetlib.Telnet(host="",port=xx,timeout=xx)

一般建议使用哪些标签

参考 推荐使用的标签

1
2
3
4
5
6
7
8
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxzy
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
    app.kubernetes.io/managed-by: helm

查看所有pod的requests limits等情况

1
[root@linux ~]# kubectl  get pods -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,PHASE:.status.phase,Request-cpu:.spec.containers\[0\].resources.requests.cpu,Request-memory:.spec.containers\[0\].resources.requests.memory,Limit-cpu:.spec.containers\[0\].resources.limits.cpu,Limit-memory:.spec.containers\[0\].resources.limits.memory -A

获取所有pod,按照cpu或者内存排序

1
2
[root@linux ~]# kubectl top pod -A --sort-by=memory
[root@linux ~]# kubectl top pod -A --sort-by=cpu

参考文档