spring-boot kubernetes cannot access the controller endpoint deployed in GKE

11/4/2017

I am trying to deploy spring-boot application in kubernetes using Google Kontainer engine(GKE=>version 1.7.8-gke.0).I have created the replication controller and service. The replication controller and service was created successfully. Please find the below output for reference,

Describe service

kubectl describe svc spring-boot-k8-service


Name:                     spring-boot-k8-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=spring-boot-k8
Type:                     NodePort
IP:                       10.59.249.64
Port:                     <unset>  9085/TCP
TargetPort:               9085/TCP
NodePort:                 <unset>  30726/TCP
Endpoints:                10.56.0.5:9085,10.56.1.3:9085,10.56.2.7:9085
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none> 

I have couple of issues here,

Cluster Details

$ gcloud container clusters list


NAME    ZONE            MASTER_VERSION  MASTER_IP       MACHINE_TYPE  
NODE_VERSION  NUM_NODES  STATUS
spring  europe-west1-d  1.7.8-gke.0     XX.XXX.XXX.XXX  g1-small      
1.7.8-gke.0   3          RUNNING

When i hit the **https://xx.xxx.xxx.xxx ** It is not popping the username/password dialog instead getting following error,

User "system:anonymous" cannot get path "/".: "No policy matched.\nUnknown user \"system:anonymous\""

The other issue is, Using which IP address i can access the service? the one in the describe response is the internal IP. I also tried with cluster master IP but no luck it is not working.

Inside the instance, I did a SSH and curl it was working fine,

curl -X GET -H "Cache-Control: no-cache" "http://localhost:32432/sayHello"
Hello.Welcome to our site!!!!

But don't know which IP i have to use to access the above endpoint externally.

Any help or pointers should will be appreciable.

-- VelNaga
cloud
google-app-engine
google-cloud-platform
kubernetes
spring

1 Answer

11/7/2017

The other issue is, Using which IP address i can access the service? the one in the describe response is the internal IP. I also tried with cluster master IP but no luck it is not working.

That part I can help you with, I think. The type: NodePort of your Service implies that it is listening inside the cluster on the IP address (and port) you see: 10.59.249.64:9085 but it is only accessible outside the cluster on the IP address of every Node on port 30726

If you wish it to be accessible to the Internet, you will need to create a load balancer, assign every Node to said load balancer, directing traffic to port 30726 of those Nodes. Or, as most people would do in that circumstance, use type: LoadBalancer to have GKE perform those exact steps for you, as described in the documentation


Separately, if you are using the same XX.XXX.XXX.XXX from your gcloud container cluster list as in your https://XX.XXX.XXX.XXX then no wonder you are getting system:anonymous errors: that is the API URL of your Kubernetes master, which (with very, very few exceptions) does not accept unauthenticated requests. It is designed to respond to kubectl actions, very similar to how you created your Service and ReplicationController that you said in the beginning.

-- mdaniel
Source: StackOverflow