Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[GRPC/Golang] Learning GRPC and Golang through the easy and actual lessons.

Posted on March 5, 2022April 28, 2022 By nim No Comments on [GRPC/Golang] Learning GRPC and Golang through the easy and actual lessons.

Hello anh em! Nếu là 1 system, 1 devops hoặc 1 devops trong hiện tại và cả tương lai.
Bạn đang băn khoăn là mà muốn học 1 ngôn ngữ lập trình nào đó!
I will suggest the Golang language to you! We will research such a power full protocol and trending which is GRPC.

Contents

Toggle
  • 1) Learning Golang GPRC.
  • 2) The actual case study!
    • 2.1) grpc With Insecure
    • 2.2) Using selfcert SSL for GRPC.
    • 2.2) Public GRPC via ingress-nginx.
      • 2.2.1) Config ingress-nginx
      • 2.2.2) Config client GRPC.
        • 2.2.2.1) Get certificates of ingress-nginx.
        • 2.2.2.2) Insecure Skip Verify TLS

1) Learning Golang GPRC.

Anh này chỉ rất hay đễ hiểu!
Nên mọi người nhớ like và surprise cho Channel của an ấy nhé!
Nếu được anh em comment thêm là tui từ nimtechnology đến đây he!!! hihi

Sau khi chiến xong hết các video thì mình có 1 số case thực tế!

2) The actual case study!

2.1) grpc With Insecure

Ta có file server.go

file client.go như sau

Ta thấy ở client chỉ đơn giản sử dụng khai báo như sau.

2.2) Using selfcert SSL for GRPC.

Trong bài học anh ấy đã chỉ rất củ thể và mình note thêm 1 số thứ!

chúng ta có file cert.conf

[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn
 
[ dn ]
C = VN
ST = HCM
L = HCM
O = Funzy.
OU = FunzyDev
emailAddress = funzydevad@gmail.com
CN = nimtechnology.com
 
[ req_ext ]
subjectAltName = @alt_names
 
[ alt_names ]
DNS.1 = localhost
DNS.2 = calculator-grpc.nimtechnology.com

Chỗ [ alt_names ] bạn sẽ lệt kê tất cả hostname hay là domain sử dụng kết nỗi giữ client và server.
vì dụ:
– localhost bạn dùng để call trên máy bạn
– calculator-grpc.nimtechnology.com bạn sự dụng để call trên dev hoặc production environment!

chúng ta có 1 file command SSLCmd.sh

openssl genrsa -out ssl/server.key 2048

openssl req -nodes -new -x509 -sha256 -days 1825 -config ssl/cert.conf -extensions 'req_ext' -key ssl/server.key -out ssl/server.crt

Khi chạy xong chúngta có mới file:

Bạn sẽ thấy file server.go như bài học:

Còn file client.go sẽ như sau:

Bạn sẽ cần lưu ý những điều sau khi mà sử dụng ssl selfcert ở client:

Làm như thầy là ngon òi.

2.2) Public GRPC via ingress-nginx.

2.2.1) Config ingress-nginx

Khi develop deploy workload GRPC lên K8s và muốn sử dụng ingress-nginx cho port GRPC đó.
đầu tiền devops cần config ingress-nginx với GPRC.
Bạn có thể tham khảo link này:
https://kubernetes.github.io/ingress-nginx/examples/grpc/

cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/backend-protocol: "GRPC"
  name: fortune-ingress
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: grpctest.dev.mydomain.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: go-grpc-greeter-server
            port:
              number: 80
  tls:
  # This secret must exist beforehand
  # The cert must also contain the subj-name grpctest.dev.mydomain.com
  # https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/PREREQUISITES.md#tls-certificates
  - secretName: wildcard.dev.mydomain.com
    hosts:
      - grpctest.dev.mydomain.com
EOF

Để Golang GRPC working với ingress-nginx thì bạn phải tạo ingress-nginx như sau
– phải tls và public port 443.
– annotation phải khai báo:
+ nginx.ingress.kubernetes.io/ssl-redirect: “true”
+ nginx.ingress.kubernetes.io/backend-protocol: “GRPC”

2.2.2) Config client GRPC.

như mình test thì case grpc With Insecure và Using selfcert SSL for GRPC thì nó không work với ingress-nginx (Port 80 & 443 TLS) he

Ủa dậy làm sao?

2.2.2.1) Get certificates of ingress-nginx.

Bạn thấy là ingress-nginx sẽ tạo ra 1 certificates cho từng ingress 443(tls)
Nhiệm vụ của chúng ta lấy nội dung certificates ghi vào file certFile := "ssl/server.crt"

trong file certificates bạn copy tls.crt và tls.key

2.2.2.2) Insecure Skip Verify TLS

Bạn chú ý chỗ này:

Bạn sẽ tham khảo thêm links này:
https://www.banquise.org/software/grpc/three-different-ways-to-connect-two-go-services-with-grpc/

Golang, Ingress

Post navigation

Previous Post: [kafka] Topic doesn’t have the record.
Next Post: [Postgresql] Install Postgres on docker easily.

More Related Articles

[go-git] returned a non-zero code: 1 when building docker Golang
[issue/alpine] docker 20.10.2 -> golang:1-alpine3.14 error: make: go: Operation not permitted Docker
[Golang] Convert between Json and Struct in Golang Golang
[Ingress Nginx] Internal error occurred: failed calling webhook “validate.nginx.ingress.kubernetes.io” Ingress
[Golang] Convert this data type to another data type in Golang Golang
[Golang] Create multiple CRON functions by looping through a list Golang

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025
  • [tracetcp] How to perform a tracert command using a specific port. April 3, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.