mirror of https://github.com/istio/istio.io.git
Service API task doc test (#8796)
* mark as tested * generate snips * test progress * add -I to curl output in command * regenerate snips * doc test fixes * Add HTTP/1.1 to expected output * change to use verify_elided
This commit is contained in:
parent
7c0ee67240
commit
6abdcec827
|
|
@ -4,7 +4,7 @@ description: Describes how to configure the Kubernetes Service APIs with Istio.
|
||||||
weight: 50
|
weight: 50
|
||||||
keywords: [traffic-management,ingress]
|
keywords: [traffic-management,ingress]
|
||||||
owner: istio/wg-networking-maintainers
|
owner: istio/wg-networking-maintainers
|
||||||
test: no
|
test: yes
|
||||||
---
|
---
|
||||||
|
|
||||||
This task describes how to configure Istio to expose a service outside of the service mesh cluster, using the Kubernetes [Service APIs](https://kubernetes-sigs.github.io/service-apis/).
|
This task describes how to configure Istio to expose a service outside of the service mesh cluster, using the Kubernetes [Service APIs](https://kubernetes-sigs.github.io/service-apis/).
|
||||||
|
|
@ -102,7 +102,7 @@ See the [Service APIs](https://kubernetes-sigs.github.io/service-apis/) document
|
||||||
1. Access the _httpbin_ service using _curl_:
|
1. Access the _httpbin_ service using _curl_:
|
||||||
|
|
||||||
{{< text bash >}}
|
{{< text bash >}}
|
||||||
$ curl -s -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/get"
|
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/get"
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
server: istio-envoy
|
server: istio-envoy
|
||||||
...
|
...
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# shellcheck disable=SC2034,SC2153,SC2155,SC2164
|
||||||
|
|
||||||
|
# Copyright Istio Authors. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL MARKDOWN FILE:
|
||||||
|
# docs/tasks/traffic-management/ingress/service-apis/index.md
|
||||||
|
####################################################################################################
|
||||||
|
|
||||||
|
snip_setup_1() {
|
||||||
|
kubectl kustomize "github.com/kubernetes-sigs/service-apis/config/crd?ref=v0.1.0" | kubectl apply -f -
|
||||||
|
}
|
||||||
|
|
||||||
|
snip_setup_2() {
|
||||||
|
istioctl install --set values.pilot.env.PILOT_ENABLED_SERVICE_APIS=true
|
||||||
|
}
|
||||||
|
|
||||||
|
snip_configuring_a_gateway_1() {
|
||||||
|
kubectl apply -f samples/httpbin/httpbin.yaml
|
||||||
|
}
|
||||||
|
|
||||||
|
snip_configuring_a_gateway_2() {
|
||||||
|
kubectl apply -f - <<EOF
|
||||||
|
apiVersion: networking.x-k8s.io/v1alpha1
|
||||||
|
kind: GatewayClass
|
||||||
|
metadata:
|
||||||
|
name: istio
|
||||||
|
spec:
|
||||||
|
controller: istio.io/gateway-controller
|
||||||
|
---
|
||||||
|
apiVersion: networking.x-k8s.io/v1alpha1
|
||||||
|
kind: Gateway
|
||||||
|
metadata:
|
||||||
|
name: gateway
|
||||||
|
namespace: istio-system
|
||||||
|
spec:
|
||||||
|
gatewayClassName: istio
|
||||||
|
listeners:
|
||||||
|
- hostname: "*"
|
||||||
|
port: 80
|
||||||
|
protocol: HTTP
|
||||||
|
routes:
|
||||||
|
namespaces:
|
||||||
|
from: All
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
selected: "yes"
|
||||||
|
kind: HTTPRoute
|
||||||
|
---
|
||||||
|
apiVersion: networking.x-k8s.io/v1alpha1
|
||||||
|
kind: HTTPRoute
|
||||||
|
metadata:
|
||||||
|
name: http
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
selected: "yes"
|
||||||
|
spec:
|
||||||
|
gateways:
|
||||||
|
allow: All
|
||||||
|
hostnames: ["httpbin.example.com"]
|
||||||
|
rules:
|
||||||
|
- matches:
|
||||||
|
- path:
|
||||||
|
type: Prefix
|
||||||
|
value: /get
|
||||||
|
filters:
|
||||||
|
- type: RequestHeaderModifier
|
||||||
|
requestHeaderModifier:
|
||||||
|
add:
|
||||||
|
my-added-header: added-value
|
||||||
|
forwardTo:
|
||||||
|
- serviceName: httpbin
|
||||||
|
port: 8000
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
snip_configuring_a_gateway_3() {
|
||||||
|
curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/get"
|
||||||
|
}
|
||||||
|
|
||||||
|
! read -r -d '' snip_configuring_a_gateway_3_out <<\ENDSNIP
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
server: istio-envoy
|
||||||
|
...
|
||||||
|
ENDSNIP
|
||||||
|
|
||||||
|
snip_configuring_a_gateway_4() {
|
||||||
|
curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/headers"
|
||||||
|
}
|
||||||
|
|
||||||
|
! read -r -d '' snip_configuring_a_gateway_4_out <<\ENDSNIP
|
||||||
|
HTTP/1.1 404 Not Found
|
||||||
|
...
|
||||||
|
ENDSNIP
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# shellcheck disable=SC1090,SC2154
|
||||||
|
|
||||||
|
# Copyright Istio Authors
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
source "tests/util/samples.sh"
|
||||||
|
|
||||||
|
# @setup profile=none
|
||||||
|
|
||||||
|
# install Service API CRDs
|
||||||
|
snip_setup_1
|
||||||
|
|
||||||
|
# install Istio with PILOT_ENABLED_SERVICE_APIS flag enabled
|
||||||
|
istioctl install --set values.pilot.env.PILOT_ENABLED_SERVICE_APIS=true -y
|
||||||
|
_wait_for_deployment istio-system istiod
|
||||||
|
_wait_for_deployment istio-system istio-ingressgateway
|
||||||
|
|
||||||
|
startup_httpbin_sample
|
||||||
|
|
||||||
|
# setup the Gateway and GatewayClass
|
||||||
|
snip_configuring_a_gateway_2
|
||||||
|
|
||||||
|
# configure $INGRESS_HOST and $INGRESS_PORT
|
||||||
|
_set_ingress_environment_variables
|
||||||
|
|
||||||
|
# send CURL traffic to http://$INGRESS_HOST:$INGRESS_PORT/get (expected 200)
|
||||||
|
_verify_elided snip_configuring_a_gateway_3 "$snip_configuring_a_gateway_3_out"
|
||||||
|
|
||||||
|
# send CURL traffic to http://$INGRESS_HOST:$INGRESS_PORT/get (expected 404)
|
||||||
|
_verify_elided snip_configuring_a_gateway_4 "$snip_configuring_a_gateway_4_out"
|
||||||
|
|
||||||
|
|
||||||
|
# @cleanup
|
||||||
|
cleanup_httpbin_sample
|
||||||
|
kubectl kustomize "github.com/kubernetes-sigs/service-apis/config/crd?ref=v0.1.0" | kubectl delete -f -
|
||||||
|
kubectl delete ns istio-system
|
||||||
Loading…
Reference in New Issue