问题
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 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
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 i.e. 192.168.65.3:8080. But I am not able to.
回答1:
Update your command to include the type to expose service on nodeport
kubectl expose deployment sv-premier --port=8080 --type=NodePort
Then your should try to reach the service using .. ip:nodeport combination
Are you using Google cloud ? The you should prefer service type=loadbalancer
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.
来源:https://stackoverflow.com/questions/60088378/access-application-deployed-on-kubernetes