Commit cfb08cd9 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #41115 from rajatchopra/kube_service_fix

Automatic merge from submit-queue fix service spec for kube api server For the auto generated kube api-server service, the service spec re-uses the service port itself. The endpoint is created correctly using public port. Fix the service also because there are some plugin controllers that react to service spec itself. Before fix: ``` sh-4.2# kubectl get endpoints NAME ENDPOINTS AGE kubernetes 172.17.0.2:8443,172.17.0.2:8053,172.17.0.2:8053 20h sh-4.2# kubectl get services kubernetes -o json ... ... "spec": { "clusterIP": "172.30.0.1", "ports": [ { "name": "https", "port": 443, "protocol": "TCP", "targetPort": 443 ## <--- same as port, even if the endpoint really means 8443 }, { "name": "dns", "port": 53, "protocol": "UDP", "targetPort": 8053 }, { "name": "dns-tcp", ... ``` After fix: ``` "spec": { "clusterIP": "172.30.0.1", "ports": [ { "name": "https", "port": 443, "protocol": "TCP", "targetPort": 8443 # <-- fixed, now matches the endpoint object }, { "name": "dns", "port": 53, "protocol": "UDP", "targetPort": 8053 }, { "name": "dns-tcp", ``
parents 7cb30052 440dcd36
...@@ -174,7 +174,7 @@ func (c *Controller) UpdateKubernetesService(reconcile bool) error { ...@@ -174,7 +174,7 @@ func (c *Controller) UpdateKubernetesService(reconcile bool) error {
return err return err
} }
servicePorts, serviceType := createPortAndServiceSpec(c.ServicePort, c.KubernetesServiceNodePort, "https", c.ExtraServicePorts) servicePorts, serviceType := createPortAndServiceSpec(c.ServicePort, c.PublicServicePort, c.KubernetesServiceNodePort, "https", c.ExtraServicePorts)
if err := c.CreateOrUpdateMasterServiceIfNeeded(kubernetesServiceName, c.ServiceIP, servicePorts, serviceType, reconcile); err != nil { if err := c.CreateOrUpdateMasterServiceIfNeeded(kubernetesServiceName, c.ServiceIP, servicePorts, serviceType, reconcile); err != nil {
return err return err
} }
...@@ -206,13 +206,13 @@ func (c *Controller) CreateNamespaceIfNeeded(ns string) error { ...@@ -206,13 +206,13 @@ func (c *Controller) CreateNamespaceIfNeeded(ns string) error {
// createPortAndServiceSpec creates an array of service ports. // createPortAndServiceSpec creates an array of service ports.
// If the NodePort value is 0, just the servicePort is used, otherwise, a node port is exposed. // If the NodePort value is 0, just the servicePort is used, otherwise, a node port is exposed.
func createPortAndServiceSpec(servicePort int, nodePort int, servicePortName string, extraServicePorts []api.ServicePort) ([]api.ServicePort, api.ServiceType) { func createPortAndServiceSpec(servicePort int, targetServicePort int, nodePort int, servicePortName string, extraServicePorts []api.ServicePort) ([]api.ServicePort, api.ServiceType) {
//Use the Cluster IP type for the service port if NodePort isn't provided. //Use the Cluster IP type for the service port if NodePort isn't provided.
//Otherwise, we will be binding the master service to a NodePort. //Otherwise, we will be binding the master service to a NodePort.
servicePorts := []api.ServicePort{{Protocol: api.ProtocolTCP, servicePorts := []api.ServicePort{{Protocol: api.ProtocolTCP,
Port: int32(servicePort), Port: int32(servicePort),
Name: servicePortName, Name: servicePortName,
TargetPort: intstr.FromInt(servicePort)}} TargetPort: intstr.FromInt(targetServicePort)}}
serviceType := api.ServiceTypeClusterIP serviceType := api.ServiceTypeClusterIP
if nodePort > 0 { if nodePort > 0 {
servicePorts[0].NodePort = int32(nodePort) servicePorts[0].NodePort = int32(nodePort)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment