新搭建的k8s集群,创建pod的时候发现使用kubectl describe pod命令查看pod状态,发现events为
kubectl describe pod data-service-589c97fc76-sjtkc -n common
Name: data-service-589c97fc76-sjtkc
Namespace: common
Priority: 0
Node: debian-3/192.168.1.197
Start Time: Sat, 25 Dec 2021 23:32:46 +0800
Labels: app=data-service
pod-template-hash=589c97fc76
Annotations:
Status: Running
IP: 10.244.2.7
IPs:
IP: 10.244.2.7
Controlled By: ReplicaSet/data-service-589c97fc76
Containers:
data-service:
Container ID: docker://1cf05406a64148328035fcd5e72d6a3140ca8f3f3a1e2e79098a78582a3864a0
Image: 192.168.1.196:80/newpathfly/data-service:0.7.1-RELEASE
Image ID: docker-pullable://192.168.1.196:80/newpathfly/data-service@sha256:1927a9ff0b2575f322e7d1ddf0e54ec4e2651d2dee70bb81c64374d18e1dc6e5
Port: 9000/TCP
Host Port: 0/TCP
State: Running
Started: Sat, 25 Dec 2021 23:32:47 +0800
Ready: True
Restart Count: 0
Limits:
cpu: 500m
memory: 1Gi
Requests:
cpu: 500m
memory: 1Gi
Environment:
JAVA_OPTS: -server -Xms256m -Xmx512m -XX:+PrintGC -XX:+PrintHeapAtGC -Xloggc:gc.log
Mounts:
/app/conf/application.conf from config-volume (rw,path="application.conf")
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9l65j (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
config-volume:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: data-service
Optional: false
kube-api-access-9l65j:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional:
DownwardAPI: true
QoS Class: Guaranteed
Node-Selectors:
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
这时不要慌,用kubectl get events -A 查看一下:
kubectl get events -A
Error from server (Forbidden): events is forbidden: User "marlin" cannot list resource "events" in API group "" at the cluster scope
原来是没有查看events的权限,只需要把对应的role.yaml里增加events权限即可。
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: cluster-reader
rules:
- apiGroups:
- ""
- "batch"
- "apps"
resources:
- pods
- nodes
- services
- cronjobs
- jobs
- endpoints
- deployments
- namespaces
- pods/log
- pods/exec
- persistentvolumes
- configmaps
- secrets
- persistentvolumeclaims
- events
verbs:
- get
- list
- watch
- delete
- create
apply之后,可以正常看到pod的events信息:
kubectl get events -A
NAMESPACE LAST SEEN TYPE REASON OBJECT MESSAGE
common 6m27s Normal Killing pod/data-service-589c97fc76-98k5g Stopping container data-service
common 6m27s Normal Scheduled pod/data-service-589c97fc76-9g57c Successfully assigned common/data-service-589c97fc76-9g57c to debian-2
common 5m44s Normal Pulling pod/data-service-589c97fc76-9g57c Pulling image "192.168.1.196:80/newpathfly/data-service:0.7.1-RELEASE"
common 5m44s Warning Failed pod/data-service-589c97fc76-9g57c Failed to pull image "192.168.1.196:80/newpathfly/data-service:0.7.1-RELEASE": rpc error: code = Unknown desc = Error response from daemon: Get "http://192.168.1.196:80/v2/": dial tcp 192.168.1.196:80: connect: connection refused
common 5m44s Warning Failed pod/data-service-589c97fc76-9g57c Error: ErrImagePull
common 5m19s Normal BackOff pod/data-service-589c97fc76-9g57c Back-off pulling image "192.168.1.196:80/newpathfly/data-service:0.7.1-RELEASE"
common 5m19s Warning Failed pod/data-service-589c97fc76-9g57c Error: ImagePullBackOff
common 5m17s Normal Scheduled pod/data-service-589c97fc76-sjtkc Successfully assigned common/data-service-589c97fc76-sjtkc to debian-3
common 5m16s Normal Pulled pod/data-service-589c97fc76-sjtkc Container image "192.168.1.196:80/newpathfly/data-service:0.7.1-RELEASE" already present on machine
common 5m16s Normal Created pod/data-service-589c97fc76-sjtkc Created container data-service
common 5m16s Normal Started pod/data-service-589c97fc76-sjtkc Started container data-service
common 6m27s Normal SuccessfulCreate replicaset/data-service-589c97fc76 Created pod: data-service-589c97fc76-9g57c
common 5m17s Normal SuccessfulCreate replicaset/data-service-589c97fc76 Created pod: data-service-589c97fc76-sjtkc
Name: data-service-589c97fc76-sjtkc
Namespace: common
Priority: 0
Node: debian-3/192.168.1.197
Start Time: Sat, 25 Dec 2021 23:32:46 +0800
Labels: app=data-service
pod-template-hash=589c97fc76
Annotations:
Status: Running
IP: 10.244.2.7
IPs:
IP: 10.244.2.7
Controlled By: ReplicaSet/data-service-589c97fc76
Containers:
data-service:
Container ID: docker://1cf05406a64148328035fcd5e72d6a3140ca8f3f3a1e2e79098a78582a3864a0
Image: 192.168.1.196:80/newpathfly/data-service:0.7.1-RELEASE
Image ID: docker-pullable://192.168.1.196:80/newpathfly/data-service@sha256:1927a9ff0b2575f322e7d1ddf0e54ec4e2651d2dee70bb81c64374d18e1dc6e5
Port: 9000/TCP
Host Port: 0/TCP
State: Running
Started: Sat, 25 Dec 2021 23:32:47 +0800
Ready: True
Restart Count: 0
Limits:
cpu: 500m
memory: 1Gi
Requests:
cpu: 500m
memory: 1Gi
Environment:
JAVA_OPTS: -server -Xms256m -Xmx512m -XX:+PrintGC -XX:+PrintHeapAtGC -Xloggc:gc.log
Mounts:
/app/conf/application.conf from config-volume (rw,path="application.conf")
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9l65j (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
config-volume:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: data-service
Optional: false
kube-api-access-9l65j:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional:
DownwardAPI: true
QoS Class: Guaranteed
Node-Selectors:
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 6m19s default-scheduler Successfully assigned common/data-service-589c97fc76-sjtkc to debian-3
Normal Pulled 6m19s kubelet Container image "192.168.1.196:80/newpathfly/data-service:0.7.1-RELEASE" already present on machine
Normal Created 6m19s kubelet Created container data-service
Normal Started 6m19s kubelet Started container data-service