1

我是 Kubernetes 新手。

以下是我正在运行的 yaml:

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: k8-demo-aishwarya
    app.kubernetes.io/version: version1
  name: k8-demo-aishwarya
spec:
  ports:
  - name: http
    port: 80
    targetPort: 80
  selector:
    app.kubernetes.io/name: k8-demo-aishwarya
    app.kubernetes.io/version: version1
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: k8-demo-aishwarya
    app.kubernetes.io/version: version1
  name: k8-demo-aishwarya
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: k8-demo-aishwarya
      app.kubernetes.io/version: version1
  template:
    metadata:
      labels:
        app.kubernetes.io/name: k8-demo-aishwarya
        app.kubernetes.io/version: version1
    spec:
      containers:
      - env:
        - name: KUBERNETES_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        image: docker.io/aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT
        imagePullPolicy: IfNotPresent
        name: k8-demo-aishwarya
        ports:
        - containerPort: 80
          name: http
          protocol: TCP

收到 crashloopbackoff 错误

谁能指导我?

图像没有问题,它运行正常,我已经在 Docker 上测试过了。

Kubernetes pod 日志如下

1. Successfully assigned default/k8-demo-aishwarya-fdd8d58c6-lvxp9 to gke-cluster-3-pool-1-997819b9-j3b2
2. Container image "docker.io/aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT" already present on machine
3. Created container k8-demo-aishwarya
4. Started container k8-demo-aishwarya
5. Back-off restarting failed container
4

2 回答 2

1

容器正在运行,正在打印 hello world 消息并退出。请参阅下面的容器日志。

$ docker ps -a
CONTAINER ID        IMAGE                                                         COMMAND                  CREATED             STATUS                      PORTS               NAMES
2b177abdbae1        aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT   "/bin/sh -c 'java ${…"   12 seconds ago      Exited (0) 10 seconds ago                       dummy


$ docker logs -f 2b1
Hello World by Aishwarya S!

如果要保持容器运行,容器内部的进程应该继续运行。您可能需要从 while 或 for 循环中打印消息。

于 2020-07-08T06:43:51.493 回答
1

请检查 POD 的日志以获取更多详细信息,但我认为这是由于处理在容器内结束并且打印Hello World by Aishwarya S!您可以通过日志检查相同的内容。

您可以通过在 YAML 中添加行来继续运行 pod:

command: ["/bin/sh", "-ec", "sleep 1000"]

此命令保持 pod 运行

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: k8-demo-aishwarya
    app.kubernetes.io/version: version1
  name: k8-demo-aishwarya
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: k8-demo-aishwarya
      app.kubernetes.io/version: version1
  template:
    metadata:
      labels:
        app.kubernetes.io/name: k8-demo-aishwarya
        app.kubernetes.io/version: version1
    spec:
      containers:
      - env:
        - name: KUBERNETES_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        image: docker.io/aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT
        command: ["/bin/sh", "-ec", "sleep 1000"]
        imagePullPolicy: IfNotPresent
        name: k8-demo-aishwarya
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
于 2020-07-08T05:05:08.373 回答