kubernetes 如何在客户端中创建服务端口go

gk7wooem  于 2022-12-03  发布在  Kubernetes
关注(0)|答案(1)|浏览(128)

我在ServiceSpec中添加端口字段时遇到问题。我做错了什么?

import (
    corev1 "k8s.io/api/core/v1"
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

    port := corev1.ServicePort{}
    port.Port = 8443
    ports := make(corev1.ServicePort, 1)

    service := &corev1.Service{
        ObjectMeta: metav1.ObjectMeta{
            Name:      "test-webhook-admissions",
            Namespace: "test",
            Labels: map[string]string{
                "app.kubernetes.io/instance": "test",
                "app.kubernetes.io/name":     "test",
                "control-plane":              "controller-manager",
            },
        },
        Spec: corev1.ServiceSpec{
            Ports:    ports, // Not working
            Selector: nil,
            //ClusterIP:                "",

        },
    }
e3bfsja2

e3bfsja21#

您必须将对象端口附加到切片端口。

相关问题