[英]Access application deployed on Kubernetes
I have my image hosted on GCR.我的图片托管在 GCR 上。 I deployed my application on local Kubernetes cluster(mac).
我在本地 Kubernetes 集群(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 get all -o wide
$ 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 get nodes -o wide
$ 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
Now as mentioned here in the accepted answer, I am trying to access my application like -- docker-desktop:NodePort ie 192.168.65.3:8080.现在,当提到这里的接受的答案,我想访问喜欢我的应用程序-泊坞窗-桌面:NodePort即192.168.65.3:8080。 But I am not able to.
但我不能。
Update your command to include the type to expose service on nodeport更新您的命令以包含在 nodeport 上公开服务的类型
kubectl expose deployment sv-premier --port=8080 --type=NodePort
Then your should try to reach the service using .. ip:nodeport combination然后您应该尝试使用 .. ip:nodeport 组合访问该服务
Are you using Google cloud ?
你在使用谷歌云吗? The you should prefer service type=loadbalancer
您应该更喜欢 service type=loadbalancer
When you create a Service of type LoadBalancer, a Google Cloud controller auto configures a network load balancer.当您创建 LoadBalancer 类型的服务时,Google Cloud 控制器会自动配置网络负载平衡器。 Wait a minute for the controller to configure the network load balancer and generate a stable IP address.
稍等片刻,让控制器配置网络负载均衡器并生成稳定的 IP 地址。 Use details from the loadbalncer to access the service.
使用负载均衡器中的详细信息来访问该服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.