访问部署在Kubernetes上的应用程序 [英] Access application deployed on Kubernetes

查看:85
本文介绍了访问部署在Kubernetes上的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的图片托管在GCR上. 我在本地Kubernetes集群(mac)上部署了我的应用程序. 这是我的部署文件-

I have my image hosted on GCR. I deployed my application on local Kubernetes cluster(mac). This is my deployment file -

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sv-premier
spec:
  selector:
    matchLabels:
      app: sv-premier
  template:
    metadata:
      labels:
        app: sv-premier
    spec:
      volumes:
      - name: google-cloud-key
        secret:
          secretName: gcp-key
      containers:
      - name: sv-premier
        image: gcr.io/proto/premiercore1:latest
        imagePullPolicy: Always
        command: ["echo", "Done deploying sv-premier"]
        volumeMounts:
        - name: google-cloud-key
          mountPath: /var/secrets/google
        env:
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /var/secrets/google/key.json
        ports:
        - containerPort: 8080
      imagePullSecrets:
      - name: imagepullsecretkey

我正在尝试访问该应用程序,但无法访问. 我将服务创建为->

I am trying to access the application but I am not able to. I created the service as -->

$ kubectl expose deployment sv-premier --port=8080 --target-port=8080
service/sv-premierleague exposed

$ kubectl get service sv-premier
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
sv-premier   ClusterIP   10.107.202.156   <none>        8080/TCP   58s

$ kubectl得到-o宽

$ kubectl get all -o wide

NAME                              READY   STATUS    RESTARTS   AGE   IP          NODE             NOMINATED NODE   READINESS GATES
pod/sv-premier-6b695d5fd7-l4995   1/1     Running   0          21h   10.1.0.45   docker-desktop   <none>           <none

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE   SELECTOR
service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP    8d    <none>
service/sv-premier   ClusterIP   10.107.202.156   <none>        8080/TCP   23m   app=sv-premier

NAME                         READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES                                    SELECTOR
deployment.apps/sv-premier   1/1     1            1           21h   sv-premier   gcr.io/sap-s4-proto/premiercore1:latest   app=sv-premier


NAME                                    DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES                                    SELECTOR
replicaset.apps/sv-premier-6b695d5fd7   1         1         1       21h   sv-premier   gcr.io/sap-s4-proto/premiercore1:latest   app=sv-premierleague,pod-template-hash=6b695d5fd7

$ kubectl获取-o宽的节点

$ kubectl get nodes -o wide

NAME             STATUS   ROLES    AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE         KERNEL-VERSION     CONTAINER-RUNTIME
docker-desktop   Ready    master   8d    v1.15.5   192.168.65.3   <none>        Docker Desktop   4.19.76-linuxkit   docker://19.3.5

现在在接受的答案中此处中提到,我正在尝试访问我的像- docker-desktop:NodePort,即192.168.65.3:8080.但是我不能.

Now as mentioned here in the accepted answer, I am trying to access my application like -- docker-desktop:NodePort i.e. 192.168.65.3:8080. But I am not able to.

推荐答案

更新您的命令以包括用于在节点端口上公开服务的类型

Update your command to include the type to expose service on nodeport

kubectl expose deployment sv-premier --port=8080 --type=NodePort

然后,您应该尝试使用.. ip:nodeport组合来获得服务

Then your should try to reach the service using .. ip:nodeport combination

您是否正在使用Google Cloud?您应该更喜欢service type = loadbalancer

Are you using Google cloud ? The you should prefer service type=loadbalancer

创建类型为LoadBalancer的服务时,Google Cloud控制器会自动配置网络负载平衡器.等待一分钟,以便控制器配置网络负载平衡器并生成稳定的IP地址.使用负载均衡器中的详细信息来访问服务.

When you create a Service of type LoadBalancer, a Google Cloud controller auto configures a network load balancer. Wait a minute for the controller to configure the network load balancer and generate a stable IP address. Use details from the loadbalncer to access the service.

这篇关于访问部署在Kubernetes上的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆