Quân Huỳnh
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Istio gateways ## Traffic ingress concepts Ingress is entry points that allows traffic go into the local network. The traffic is first routed to an ingress point and the ingress point enforces rules and policies about what traffic is allowed into the local network. If the ingress point allows the traffic, it proxies the traffic to the correct endpoint in the local network. If the traffic is not allowed, the ingress point rejects the traffic. Virtual IPs - a type of ingress point known as a reverse proxy. ![](https://i.imgur.com/KKi76hG.png) Virtual hosting - multiple services from a single access point. We need a way to decide which virtual host group a particular request should be routed to: + HTTP/1.1, we can use the `Host` header + HTTP/2, we can use the `:authority` header + TCP connections, we can rely on `Server Name Indication (SNI)` with TLS ![](https://i.imgur.com/fFvyJOU.png) ## Istio ingress gateways Istio has the concept of an *Ingress Gateway* that plays the role of the network ingress point. Additionally, Istio’s ingress gateway handles load balancing and virtual-host routing. ![](https://i.imgur.com/H95tiC7.png) We’ll start by exploring two Istio resources: Gateway and VirtualService. ### Gateway resources To configure an ingress gateway in Istio, we use the Gateway resource. ```bash kubectl apply -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: coolstore-gateway spec: selector: istio: ingressgateway servers: - port: number: 80 name: http protocol: HTTP hosts: - "webapp.istioinaction.io" EOF ``` Let’s see whether our settings took effect: ```bash istioctl -n istio-system proxy-config listener deploy/istio-ingressgateway ``` Next, we set up a virtual host to route traffic from port 80 to a service within the service mesh. ### VirtualService resources We’ll use the *VirtualService* resource to get the traffic comes into the gateway to a specific service within the service mesh. ```bash kubectl apply -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: webapp-vs-from-gw spec: hosts: - "webapp.istioinaction.io" gateways: - coolstore-gateway http: - route: - destination: host: webapp port: number: 80 EOF ``` we can run our commands to list the listeners and routes: ```bash istioctl proxy-config route deploy/istio-ingressgateway -o json --name http.8080 -n istio-system ``` Let's test: ``` curl http://localhost/api/catalog -H "Host: webapp.istioinaction.io" ``` ### Istio Ingress Gateway vs Kubernetes Ingress Kubernetes Ingress have some limitations: + The first limitation is that Kubernetes Ingress v1 is a very simple specification geared toward HTTP workloads + The second is the Ingress specification only considers port 80 and port 443 as ingress points, this severely limits the types of traffic a cluster operator can allow into the service mesh. For examples, Kafka or NATS workloads or direct TCP connections + Annotations of configuration between vendors vary and are not portable => Kubernetes Ingress doesn’t allow for that. Ultimately, Istio decided on a clean slate for building ingress patterns and specifically separated out the layer 4 (transport) and layer 5 (session) properties from the layer 7 (application) routing concerns. Istio Gateway handles the L4 and L5 concerns, while VirtualService handles the L7 concerns. ### HTTP traffic with TLS Creating a Kubernetes secrets to store certificates and keys. ```bash kubectl create -n istio-system secret tls webapp-credential --key webapp.istioinaction.io.key.pem --cert webapp.istioinaction.io.cert.pem ``` The default gateway is run in the `istio-system` namespace, so that’s where we put the secret. Now we can configure our Istio Gateway resource to use the certificates and keys: ```yaml apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: coolstore-gateway spec: selector: istio: ingressgateway servers: - port: number: 80 name: http protocol: HTTP hosts: - "webapp.istioinaction.io" - port: number: name: https protocol: HTTPS tls: mode: SIMPLE credentialName: webapp-credential hosts: - "webapp.istioinaction.io" ``` Updating it, and if we call the service as we did in the previous section, by passing in the proper `Host` header, we will see error as below: ``` * Trying 127.0.0.1... * TCP_NODELAY set * Connected to localhost (127.0.0.1) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs * TLSv1.3 (OUT), TLS handshake, Client hello (1): * OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:443 * stopped the pause stream! * Closing connection 0 curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:443 ``` Let’s pass in the proper CA certificate chain to our curl client: ``` curl -v -H "Host: webapp.istioinaction.io" https://localhost/api/catalog --cacert ca-chain.cert.pem --resolve webapp.istioinaction.io:443:127.0.0.1 ``` ![](https://i.imgur.com/EasSn7e.png) For HTTP redirect to HTTPS ``` tls: httpsRedirect: true ``` ```yaml apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: coolstore-gateway spec: selector: istio: ingressgateway servers: - port: number: 80 name: http protocol: HTTP tls: httpsRedirect: true hosts: - "webapp.istioinaction.io" - port: number: 443 name: https protocol: HTTPS tls: mode: SIMPLE credentialName: webapp-credential hosts: - "webapp.istioinaction.io" ``` ### Serving multiple virtual hosts with TLS Istio’s ingress gateway can serve multiple virtual hosts, each with its own certificate and private key from the same HTTPS port (port 443). ```yaml apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: coolstore-gateway spec: selector: istio: ingressgateway servers: - port: number: 443 name: https-webapp protocol: HTTPS tls: mode: SIMPLE credentialName: webapp-credential hosts: - "webapp.istioinaction.io" - port: number: 443 name: https-catalog protocol: HTTPS tls: mode: SIMPLE credentialName: catalog-credential hosts: - "catalog.istioinaction.io" ``` ``` curl -H "Host: webapp.istioinaction.io" http://localhost:80/api/catalog ``` ```bash kubectl apply -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: catalog-vs-from-gw spec: hosts: - "catalog.istioinaction.io" gateways: - coolstore-gateway http: - route: - destination: host: catalog port: number: 80 EOF ``` ``` curl -H "Host: catalog.istioinaction.io" http://localhost:80/items ``` ### TCP traffic Istio’s gateway is powerful enough to serve not only HTTP/HTTPS traffic but also any traffic accessible via TCP. Let's deploy simple TCP server. ```bash kubectl apply -f - <<EOF apiVersion: apps/v1 kind: Deployment metadata: name: tcp-echo-deployment labels: app: tcp-echo system: example spec: replicas: 1 selector: matchLabels: app: tcp-echo template: metadata: labels: app: tcp-echo system: example spec: containers: - name: tcp-echo-container image: cjimti/go-echo:latest imagePullPolicy: IfNotPresent env: - name: TCP_PORT value: "2701" - name: NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: POD_IP valueFrom: fieldRef: fieldPath: status.podIP - name: SERVICE_ACCOUNT valueFrom: fieldRef: fieldPath: spec.serviceAccountName ports: - name: tcp-echo-port containerPort: 2701 --- apiVersion: v1 kind: Service metadata: name: "tcp-echo-service" labels: app: tcp-echo system: example spec: selector: app: "tcp-echo" ports: - protocol: "TCP" port: 2701 targetPort: 2701 EOF ``` In the following example, we expose port 31400 on the default `istioingressgateway`. ```bash kubectl apply -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: echo-tcp-gateway spec: selector: istio: ingressgateway servers: - port: number: 31400 name: tcp-echo protocol: TCP hosts: - "*" EOF ``` Any host: ```yaml hosts: - "*" ``` Checking service is listening for TCP. ```bash kubectl get svc -n istio-system istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name == "tcp")]}' | jq -r ``` Now that we’ve exposed a port on our ingress gateway, we need to route the traffic to the echo service with VirtualService. ```bash kubectl apply -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: tcp-echo-vs-from-gw spec: hosts: - "*" gateways: - echo-tcp-gateway tcp: - match: - port: 31400 route: - destination: host: tcp-echo-service port: number: 2701 EOF ``` > **NOTE** If you’re running in a public cloud or a cluster that creates a LoadBalancer for the istio-ingressgateway service, and you can’t connect as shown next, you may need to explicitly add a port to the istio-ingressgateway service on port 31400 and use targetPort 31400 for this to work correctly. Let's test. ``` telnet localhost 31400 ``` ### Traffic routing with SNI passthrough ```bash kubectl apply -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: sni-passthrough-gateway spec: selector: istio: ingressgateway servers: - port: number: 31400 name: tcp-sni protocol: TLS hosts: - "simple-sni-1.istioinaction.io" tls: mode: PASSTHROUGH EOF ``` In our example application, we configure the application to terminate TLS for the HTTPS connection using certificates. This means we don’t need the ingress gateway to do anything with the connection. We won’t need to configure any certificates on the gateway. All the gateway will do is inspect the SNI headers and route the traffic to the specific backend, which will then terminate the TLS connection. The connection will “pass through” the gateway and be handled by the actual service, not the gateway. Next, we define a VirtualService to specify routing rules. ```bash kubectl apply -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: simple-sni-1-vs spec: hosts: - "simple-sni-1.istioinaction.io" gateways: - sni-passthrough-gateway tls: - match: - port: 31400 sniHosts: - simple-sni-1.istioinaction.io route: - destination: host: simple-tls-service-1 port: number: 80 EOF ``` ### Ingress gateway access logs A common feature for a proxy is logging every individual request that it processes. These access logs are helpful for troubleshooting issues. But in the production, Istio access logs is disabled when using the *default* profile. You can turn on access logging with the following command: ```bash istioctl install --set meshConfig.accessLogFile=/dev/stdout ``` A better approach is to enable access logging only for the workloads for which you are interested in using the *Telemetry* API. For example, to show the access logs of only the ingress gateway workloads: ```bash kubectl apply -f - <<EOF apiVersion: telemetry.istio.io/v1alpha1 kind: Telemetry metadata: name: ingress-gateway namespace: istio-system spec: selector: matchLabels: app: istio-ingressgateway accessLogging: - providers: - name: envoy disabled: false EOF ``` Istio configuration can be applied in different scopes: + Mesh-wide + Namespace-wide + Workload-specific ###### tags: `istio`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully