gpt4 book ai didi

docker - 无法访问 kubernetes minikube 上的 IP 和 PORT

转载 作者:行者123 更新时间:2023-12-02 21:32:54 27 4
gpt4 key购买 nike

我在 kubernetes 上创建了 web 部署和服务
当我用 $ kubectl get service 列出服务时命令列出访问网页的 IP 和端口,但是当我尝试访问它时,无法访问该站点。
minikube 上的 kubernetes 似乎没有从 docker hub 拉取镜像。
这是我的示例脚本..
我使用 Kubernetes v1.19.2 和默认驱动程序 Docker 19.03.8

  • $ kubectl create -f web-pets.yaml

  • apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: web
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: pets
    service: web
    template:
    metadata:
    labels:
    app: pets
    service: web
    spec:
    containers:
    - image: nginx:alpine-1.19.2
    name: web
    ports:
    - containerPort: 80
    protocol: TCP
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: web
    spec:
    type: NodePort
    ports:
    - port: 80
    protocol: TCP
    selector:
    app: pets
    service: web

  • 输出创建 web-pets.yaml

  • $ kubectl create -f web-pets.yaml
    deployment.apps/web created
    service/web created

  • 输出 $ kubectl get service

  • $ kubectl get service
    NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 11h
    web NodePort 10.110.107.234 <none> 80:30100/TCP 41s

  • 输出 $ kubectl get service web

  • Name:                     web
    Namespace: default
    Labels: <none>
    Annotations: <none>
    Selector: app=pets,service=web
    Type: NodePort
    IP: 10.109.10.68
    Port: <unset> 3000/TCP
    TargetPort: 3000/TCP
    NodePort: <unset> 31830/TCP
    Endpoints: <none>
    Session Affinity: None
    External Traffic Policy: Cluster
    Events: <none>

  • 当列出所有 docker 镜像时,没有 nginx 镜像

  • $ docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    kicbase/stable v0.0.12-snapshot3 25ac91b9c8d7 4 weeks ago 952MB
    gcr.io/k8s-minikube/kicbase v0.0.12-snapshot3 25ac91b9c8d7 4 weeks ago 952MB

  • 部署网页描述

  • $ kubectl describe deploy web
    Name: web
    Namespace: default
    CreationTimestamp: Thu, 24 Sep 2020 17:25:42 +0700
    Labels: <none>
    Annotations: <none>
    Selector: app=pets,service=web
    Replicas: 1 desired | 0 updated | 0 total | 0 available | 0 unavailable
    StrategyType: RollingUpdate
    MinReadySeconds: 0
    RollingUpdateStrategy: 25% max unavailable, 25% max surge
    Pod Template:
    Labels: app=pets
    service=web
    Containers:
    web:
    Image: nginx:alpine-1.19.2
    Port: 3000/TCP
    Host Port: 0/TCP
    Environment: <none>
    Mounts: <none>
    Volumes: <none>
    OldReplicaSets: <none>
    NewReplicaSet: <none>
    Events: <none>

  • $ kubectl get pods

  • $ kubectl get pods
    No resources found in default namespace.

  • $ kubectl get events

  • LAST SEEN   TYPE     REASON                    OBJECT          MESSAGE
    7m13s Normal Starting node/minikube Starting kubelet.
    7m11s Normal NodeHasSufficientMemory node/minikube Node minikube status is now: NodeHasSufficientMemory
    7m11s Normal NodeHasNoDiskPressure node/minikube Node minikube status is now: NodeHasNoDiskPressure
    7m11s Normal NodeHasSufficientPID node/minikube Node minikube status is now: NodeHasSufficientPID
    7m12s Normal NodeAllocatableEnforced node/minikube Updated Node Allocatable limit across pods
    6m28s Normal Starting node/minikube Starting kube-proxy.

    最佳答案

    Nginx 监听端口 80 .因此你需要使用端口 80而不是端口 3000在部署和服务中。来自 docs你应该能够使用它访问它minikube service web

    关于docker - 无法访问 kubernetes minikube 上的 IP 和 PORT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64043509/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com