簡體   English   中英

使用 Kubernetes 部署 YAML 文件將 Docker 映像部署到 Google Cloud 時未創建任何 pod

[英]No pods created when deploying a Docker image to Google Cloud using a Kubernetes deployment YAML file

嘗試使用 Kubernetes YAML 文件在 Google Cloud 上創建部署時遇到問題。 我看到使用 YAML 文件時沒有創建任何 pod; 但是,如果我使用kubectl create deployment... ,確實會創建 pod。

我的 YAML 文件如下:

#Deployment
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
  generation: 1
  labels:
    app: hello-world
  name: hello-world
  namespace: default
  resourceVersion: "3691124"
spec:
  progressDeadlineSeconds: 600
  replicas: 3
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: hello-world
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - image: myrepo/hello-world:0.0.4.RELEASE
        imagePullPolicy: IfNotPresent
        name: hello-world
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
#Service
apiVersion: v1
kind: Service
metadata:
  labels:
    app: hello-world
  name: hello-world
  namespace: default
  resourceVersion: "3691877"
spec:
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 32448
    port: 8080
    protocol: TCP
    targetPort: 8001
  selector:
    app: hello-world
  sessionAffinity: None
  type: LoadBalancer

這是我在運行kubectl get all時看到的:

NAME                           TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)          AGE
service/hello-world            LoadBalancer   Some IP        Some IP 3     8001:32449/TCP    15m
service/kubernetes             ClusterIP      Some IP 2      <none>         444/TCP           12d

如您所見,啟動的唯一資源是服務。 我既沒有看到任何部署,也沒有看到任何正在創建的 pod。

請注意,出於顯而易見的原因,我已將實際的 IP 地址替換為上面的“某些 IP”。

問:為什么我使用 YAML 時沒有創建 pod,但使用kubectl create deployment而不是使用 YAML 配置文件時創建了 pod?

  1. 當您在單個文件中有多個資源時,您應該在 YAML 中使用---
  2. 您必須在部署中設置apiVersion: apps/v1
---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
  generation: 1
  labels:
    app: hello-world
  name: hello-world
  namespace: default
  resourceVersion: "3691124"
spec:
  progressDeadlineSeconds: 600
  replicas: 3
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: hello-world
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - image: myrepo/hello-world:0.0.4.RELEASE
        imagePullPolicy: IfNotPresent
        name: hello-world
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: hello-world
  name: hello-world
  namespace: default
  resourceVersion: "3691877"
spec:
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 32448
    port: 8080
    protocol: TCP
    targetPort: 8001
  selector:
    app: hello-world
  sessionAffinity: None
  type: LoadBalancer

Output

$ kubectl get deply,po,svc
NAME                          READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/hello-world   0/3     3            0           5m34s

NAME                               READY   STATUS             RESTARTS   AGE

pod/hello-world-6bd8d58486-7lzh9   0/1     ImagePullBackOff   0          3m49s
pod/hello-world-6bd8d58486-m56rq   0/1     ImagePullBackOff   0          3m49s
pod/hello-world-6bd8d58486-z9xmz   0/1     ImagePullBackOff   0          3m49s

NAME                  TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE
service/hello-world   LoadBalancer   10.108.65.81     <pending>     8080:32448/TCP    3m49s
service/kubernetes    ClusterIP      10.96.0.1        <none>        443/TCP           9d

最佳實踐是為不同的資源創建不同的 yaml 文件。 如果您需要將 package 多個 kubernetes 資源整合到一個實體中,請使用 Helm。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM