lgy1027 commented on issue #631:
URL: 
https://github.com/apache/apisix-ingress-controller/issues/631#issuecomment-900757241


   > 
@lgy1027请阅读http://apisix.apache.org/了解更多详情,例如:[http](http://apisix.apache.org/docs/apisix/grpc-proxy/)
 : //apisix.apache.org/docs/apisix/grpc-proxy/。
   
   
感谢回复,但是看着文档更多的是http直接请求设置参数,我现在需要的是通过k8s完成交互,目前我想测试的是一个svc暴漏两个端口,一个是http端口,还有个是grpc端口,然后针对grpc需要单独创建upstream,但是我看官网说grpc需要设置证书,请问证书在哪里设置,是创建ApisixTls设置吗,然后证书如何和grpc关联,针对这个场景有很多疑问,主要是官网对ingress
 controller的文档不太友好,示例很少,还有就是helm安装apisix,crd没有betal版本,以下是我创建的实例。
   ````
   func Test_Client(t *testing.T)  {
        BuildCons()
        BuildRoute()
        BuildApiSixUpStream()
   }
   
   func BuildApiSixUpStream()  {
        http := &apisixv1.ApisixUpstream{
                ObjectMeta:metav1.ObjectMeta{
                        Name: "httpbin-http",
                        Namespace: "lgy",
                },
                Spec: &apisixv1.ApisixUpstreamSpec{
                        PortLevelSettings:[]apisixv1.PortLevelSettings{
                                apisixv1.PortLevelSettings{
                                        Port: 80,
                                        
ApisixUpstreamConfig:apisixv1.ApisixUpstreamConfig{
                                                Scheme:"http",
                                        },
                                },
                        },
   
                },
        }
        grpc := &apisixv1.ApisixUpstream{
                ObjectMeta:metav1.ObjectMeta{
                        Name: "httpbin-grpc",
                        Namespace: "lgy",
                },
                Spec: &apisixv1.ApisixUpstreamSpec{
                        PortLevelSettings:[]apisixv1.PortLevelSettings{
                                apisixv1.PortLevelSettings{
                                        Port: 81,
                                        
ApisixUpstreamConfig:apisixv1.ApisixUpstreamConfig{
                                                Scheme:"grpc",
                                        },
                                },
                        },
   
                },
        }
        result, err := 
client.ApisixV1().ApisixUpstreams("lgy").Create(context.TODO(),http,v1.CreateOptions{})
        fmt.Println(err)
        fmt.Println(result)
        result, err = 
client.ApisixV1().ApisixUpstreams("lgy").Create(context.TODO(),grpc,v1.CreateOptions{})
        fmt.Println(err)
        fmt.Println(result)
        apisixv1.ApisixTls{}
   }
   
   func BuildCons()  {
        cons := &v2alpha1.ApisixConsumer{
                ObjectMeta:metav1.ObjectMeta{
                        Name: "test",
                        Namespace: "lgy",
                },
                Spec:v2alpha1.ApisixConsumerSpec{
                        AuthParameter:v2alpha1.ApisixConsumerAuthParameter{
                                KeyAuth:&v2alpha1.ApisixConsumerKeyAuth{
                                        //Value: 
&v2alpha1.ApisixConsumerKeyAuthValue{
                                        //      Key: "lgy",
                                        //},
                                        SecretRef:&corev1.LocalObjectReference{
                                                Name: "mysecret",
                                        },
                                },
                        },
                },
        }
        result, err := 
client.ApisixV2alpha1().ApisixConsumers("lgy").Create(context.TODO(),cons,v1.CreateOptions{})
        fmt.Println(err)
        fmt.Println(result)
   }
   
   func BuildRoute()  {
        w := int(100)
        http := &v2alpha1.ApisixRoute{
                ObjectMeta:metav1.ObjectMeta{
                        Name: "test-lgy-http",
                        Namespace: "lgy",
                },
                Spec:&v2alpha1.ApisixRouteSpec{
                        HTTP: []*v2alpha1.ApisixRouteHTTP{
                                &v2alpha1.ApisixRouteHTTP{
                                        Name: "http",
                                        Match: &v2alpha1.ApisixRouteHTTPMatch{
                                                Hosts: 
[]string{"local.httpbin.org"},
                                                Paths: []string{"/*"},
                                        },
                                        Backends: 
[]*v2alpha1.ApisixRouteHTTPBackend{
                                                
&v2alpha1.ApisixRouteHTTPBackend{
                                                        ServiceName: 
"httpbin-http",
                                                        ServicePort: 
intstr.IntOrString{
                                                                Type: 
intstr.Int,
                                                                IntVal: 80,
                                                        },
                                                        Weight:&w,
                                                },
                                        },
                                        Authentication: 
&v2alpha1.ApisixRouteAuthentication{
                                                Enable: true,
                                                Type: "keyAuth",
                                        },
                                        Plugins: 
[]*v2alpha1.ApisixRouteHTTPPlugin{
                                                &v2alpha1.ApisixRouteHTTPPlugin{
                                                        
Config:v2alpha1.ApisixRouteHTTPPluginConfig{
                                                                
"whitelist":[]string{"lgy_test"},
                                                        },
                                                        Enable:true,
                                                        Name: 
"consumer-restriction",
                                                },
                                        },
                                },
                        },
                },
        }
   
        grpc := &v2alpha1.ApisixRoute{
                ObjectMeta:metav1.ObjectMeta{
                        Name: "test-lgy-grpc",
                        Namespace: "lgy",
                },
                Spec:&v2alpha1.ApisixRouteSpec{
                        HTTP: []*v2alpha1.ApisixRouteHTTP{
                                &v2alpha1.ApisixRouteHTTP{
                                        Name: "grpc",
                                        Match: &v2alpha1.ApisixRouteHTTPMatch{
                                                Hosts: 
[]string{"local.httpbin.org"},
                                                Paths: []string{"/*"},
                                        },
                                        Backends: 
[]*v2alpha1.ApisixRouteHTTPBackend{
                                                
&v2alpha1.ApisixRouteHTTPBackend{
                                                        ServiceName: 
"httpbin-grpc",
                                                        ServicePort: 
intstr.IntOrString{
                                                                Type: 
intstr.Int,
                                                                IntVal: 81,
                                                        },
                                                        Weight:&w,
                                                },
                                        },
                                        Authentication: 
&v2alpha1.ApisixRouteAuthentication{
                                                Enable: true,
                                                Type: "keyAuth",
                                        },
                                        Plugins: 
[]*v2alpha1.ApisixRouteHTTPPlugin{
                                                &v2alpha1.ApisixRouteHTTPPlugin{
                                                        
Config:v2alpha1.ApisixRouteHTTPPluginConfig{
                                                                
"whitelist":[]string{"lgy_test"},
                                                        },
                                                        Enable:true,
                                                        Name: 
"consumer-restriction",
                                                },
                                        },
                                },
                        },
                },
        }
        result, err := 
client.ApisixV2alpha1().ApisixRoutes("lgy").Create(context.TODO(),http,v1.CreateOptions{})
        fmt.Println(err)
        fmt.Println(result)
        result, err = 
client.ApisixV2alpha1().ApisixRoutes("lgy").Create(context.TODO(),grpc,v1.CreateOptions{})
        fmt.Println(err)
        fmt.Println(result)
   }
   ````
   
   
![image](https://user-images.githubusercontent.com/38779388/129825351-d2bfab6e-ea6b-4600-8dce-d3a0eb49e2df.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to