在Client go中创建服务端口是一项重要的技能,对于开发人员来说至关重要。通过创建服务端口,可以实现客户端与服务器之间的通信,从而实现数据的传输和交互。本文将由php小编新一为大家介绍如何在Client go中创建服务端口,帮助开发人员更好地掌握这一技能。让我们一起来了解吧!
我在 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: "", }, }
这对我有用
func GetLabels() map[string]string { return map[string]string{ "app.kubernetes.io/instance": "test", "app.kubernetes.io/name": "test", "control-plane": "controller-manager", } } service := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: "test-webhook-admissions", Namespace: namespace, Labels: GetLabels(), }, Spec: corev1.ServiceSpec{ Ports: []corev1.ServicePort{ { Name: "webhook", Port: 8443, TargetPort: intstr.FromInt(8443), Protocol: "TCP", }, }, Selector: GetLabels(), }, } err := w.Client.Create(context.Background(), service)
以上是如何在Client go中创建服务端口的详细内容。更多信息请关注PHP中文网其他相关文章!