Skip to content

Commit 6fc5123

Browse files
akhurana001liyinan926
authored andcommitted
Replace NodePort Service with ClusterIP (#520)
* Remove NodePort Service * Docs update
1 parent 52ff900 commit 6fc5123

File tree

7 files changed

+13
-40
lines changed

7 files changed

+13
-40
lines changed

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ A `DriverInfo` captures information about the driver pod and the Spark web UI ru
147147
| ------------- | ------------- |
148148
| `WebUIServiceName` | Name of the service for the Spark web UI. |
149149
| `WebUIPort` | Port on which the Spark web UI runs on the Node. |
150-
| `WebUIAddress` | Address to access the web UI from outside the cluster via the Node. |
150+
| `WebUIAddress` | Address to access the web UI from within the cluster. |
151151
| `WebUIIngressName` | Name of the ingress for the Spark web UI. |
152152
| `WebUIIngressAddress` | Address to access the web UI via the Ingress. |
153153
| `PodName` | Name of the driver pod. |

docs/quick-start-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ and deleting the pods outside the operator might lead to incorrect metric values
199199

200200
## Driver UI Access and Ingress
201201

202-
The operator, by default, makes the Spark UI accessible by creating a service of type `NodePort` which exposes the UI via the node running the driver.
202+
The operator, by default, makes the Spark UI accessible by creating a service of type `ClusterIP` which exposes the UI. This is only accessible from within the cluster.
203203
The operator also supports creating an Ingress for the UI. This can be turned on by setting the `ingress-url-format` command-line flag. The `ingress-url-format` should be a template like `{{$appName}}.ingress.cluster.com` and the operator will replace the `{{$appName}}` with the appropriate appName.
204204

205-
The operator also sets both `WebUIAddress` which uses the Node's public IP as well as `WebUIIngressAddress` as part of the `DriverInfo` field of the `SparkApplication`.
205+
The operator also sets both `WebUIAddress` which is accessible from within the cluster as well as `WebUIIngressAddress` as part of the `DriverInfo` field of the `SparkApplication`.
206206

207207
## About the Mutating Admission Webhook
208208

pkg/apis/sparkoperator.k8s.io/v1alpha1/types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ const (
422422
// DriverInfo captures information about the driver.
423423
type DriverInfo struct {
424424
WebUIServiceName string `json:"webUIServiceName,omitempty"`
425-
// UI Details for the UI created via NodePort service.
426-
// TODO: Remove this in favor of UI access via Ingress.
425+
// UI Details for the UI created via ClusterIP service accessible from within the cluster.
427426
WebUIPort int32 `json:"webUIPort,omitempty"`
428427
WebUIAddress string `json:"webUIAddress,omitempty"`
429428
// Ingress Details if an ingress for the UI was created.

pkg/apis/sparkoperator.k8s.io/v1beta1/types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,7 @@ const (
457457
// DriverInfo captures information about the driver.
458458
type DriverInfo struct {
459459
WebUIServiceName string `json:"webUIServiceName,omitempty"`
460-
// UI Details for the UI created via NodePort service.
461-
// TODO: Remove this in favor of UI access via Ingress.
460+
// UI Details for the UI created via ClusterIP service accessible from within the cluster.
462461
WebUIPort int32 `json:"webUIPort,omitempty"`
463462
WebUIAddress string `json:"webUIAddress,omitempty"`
464463
// Ingress Details if an ingress for the UI was created.

pkg/controller/sparkapplication/controller.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,6 @@ func (c *Controller) getAndUpdateDriverState(app *v1beta1.SparkApplication) erro
312312
return nil
313313
}
314314

315-
if driverPod.Spec.NodeName != "" {
316-
if nodeIP := c.getNodeIP(driverPod.Spec.NodeName); nodeIP != "" {
317-
app.Status.DriverInfo.WebUIAddress = fmt.Sprintf("%s:%d", nodeIP, app.Status.DriverInfo.WebUIPort)
318-
}
319-
}
320315
app.Status.SparkApplicationID = getSparkApplicationID(driverPod)
321316

322317
if driverPod.Status.Phase == apiv1.PodSucceeded || driverPod.Status.Phase == apiv1.PodFailed {
@@ -659,7 +654,8 @@ func (c *Controller) submitSparkApplication(app *v1beta1.SparkApplication) *v1be
659654
glog.Errorf("failed to create UI service for SparkApplication %s/%s: %v", app.Namespace, app.Name, err)
660655
} else {
661656
app.Status.DriverInfo.WebUIServiceName = service.serviceName
662-
app.Status.DriverInfo.WebUIPort = service.nodePort
657+
app.Status.DriverInfo.WebUIPort = service.servicePort
658+
app.Status.DriverInfo.WebUIAddress = fmt.Sprintf("%s:%d", service.serviceIP, app.Status.DriverInfo.WebUIPort)
663659
// Create UI Ingress if ingress-format is set.
664660
if c.ingressURLFormat != "" {
665661
ingress, err := createSparkUIIngress(app, *service, c.ingressURLFormat, c.kubeClient)
@@ -823,27 +819,6 @@ func (c *Controller) enqueue(obj interface{}) {
823819
c.queue.AddRateLimited(key)
824820
}
825821

826-
// Return IP of the node. If no External IP is found, Internal IP will be returned
827-
func (c *Controller) getNodeIP(nodeName string) string {
828-
node, err := c.kubeClient.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
829-
if err != nil {
830-
glog.Errorf("failed to get node %s", nodeName)
831-
return ""
832-
}
833-
834-
for _, address := range node.Status.Addresses {
835-
if address.Type == apiv1.NodeExternalIP {
836-
return address.Address
837-
}
838-
}
839-
for _, address := range node.Status.Addresses {
840-
if address.Type == apiv1.NodeInternalIP {
841-
return address.Address
842-
}
843-
}
844-
return ""
845-
}
846-
847822
func (c *Controller) recordSparkApplicationEvent(app *v1beta1.SparkApplication) {
848823
switch app.Status.AppState.State {
849824
case v1beta1.NewState:

pkg/controller/sparkapplication/sparkui.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func getSparkUIingressURL(ingressURLFormat string, appName string) string {
4848
type SparkService struct {
4949
serviceName string
5050
servicePort int32
51-
nodePort int32
51+
serviceIP string
5252
}
5353

5454
// SparkIngress encapsulates information about the driver UI ingress.
@@ -124,7 +124,7 @@ func createSparkUIService(
124124
config.SparkAppNameLabel: app.Name,
125125
config.SparkRoleLabel: config.SparkDriverRole,
126126
},
127-
Type: apiv1.ServiceTypeNodePort,
127+
Type: apiv1.ServiceTypeClusterIP,
128128
},
129129
}
130130

@@ -136,8 +136,8 @@ func createSparkUIService(
136136

137137
return &SparkService{
138138
serviceName: service.Name,
139-
servicePort: int32(port),
140-
nodePort: service.Spec.Ports[0].NodePort,
139+
servicePort: service.Spec.Ports[0].Port,
140+
serviceIP: service.Spec.ClusterIP,
141141
}, nil
142142
}
143143

pkg/controller/sparkapplication/sparkui_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func TestCreateSparkUIService(t *testing.T) {
6767
if !reflect.DeepEqual(test.expectedSelector, service.Spec.Selector) {
6868
t.Errorf("%s: for label selector wanted %s got %s", test.name, test.expectedSelector, service.Spec.Selector)
6969
}
70-
if service.Spec.Type != apiv1.ServiceTypeNodePort {
71-
t.Errorf("%s: for service type wanted %s got %s", test.name, apiv1.ServiceTypeNodePort, service.Spec.Type)
70+
if service.Spec.Type != apiv1.ServiceTypeClusterIP {
71+
t.Errorf("%s: for service type wanted %s got %s", test.name, apiv1.ServiceTypeClusterIP, service.Spec.Type)
7272
}
7373
if len(service.Spec.Ports) != 1 {
7474
t.Errorf("%s: wanted a single port got %d ports", test.name, len(service.Spec.Ports))

0 commit comments

Comments
 (0)