趣å³GKEã®Ingressãç¡æã§æ¸ã¾ãã
GKEã§ãµã¼ãã¹ãå¤é¨å ¬éããéã«ã¯ã GKE Ingress ã¨ãã®ããã¯ã¨ã³ã GCP Cloud Load Balancing ã使ç¨ããã®ãã¹ã¿ã³ãã¼ãã§ããããããã«ã¯è²»ç¨ ($18/æ~) ããããã¾ãã
ãããCloudflare DNS + Contourã§ç½®ãæãã¦ãç¡æã§æ¸ã¾ããæ¹æ³ã説æãã¾ãããã¼ãã¯å ¨å°ããªã¨ã³ããã£ãã¤ã³ã¹ã¿ã³ã¹ã§æ§ãã¾ããã
ãã®è¨äºã¯Doxseyããã«ãã Kubernetes: The Surprisingly Affordable Platform for Personal Projects ãçºå±ãããå 容ã«ãªãã¾ãã å è¨äºã¨åæ§ãç´¹ä»ããæ§æã¯è¶£å³å©ç¨ã«ã¨ã©ãã¦ãã ããã
GKEã¯ã©ã¹ã¿ä½æ
ã¾ãGKEã¯ã©ã¹ã¿ãä½æãã¦ãã ããã3å°ä»¥ä¸ã§æ§ç¯ããããªã¨ã³ããã£ããæå¹ã«ããã®ããªã¹ã¹ã¡ã§ãã
ã¡ãªã¿ã«Doxseyããã®è¨äºã§ã¯f1-microã使ã£ã¦ãã¾ããã 2020å¹´4æ18æ¥ç¾å¨ãf1-microã§ã¯GKEã®ã¯ã¼ã«ã¼ãã¼ãã¨ãã¦æä½éå¿ è¦ãªã·ã¹ãã ã³ã³ãã¼ãã³ãããã¾ã¨ãã«åããªãããã§ãã e2-smallã«ãã¾ãããã
Nodeã¸ã®HTTP/HTTPSã¢ã¯ã»ã¹ã許å¯
ãã¡ã¤ã¢ã¦ã©ã¼ã«è¨å®ã§ TCP/UDPåæ¹ã®80ã»443ãã¼ãingressã許å¯ãã¾ãããã ãã®æé ã¯Doxseyããã®è¨äºã«å«ã¾ãã¦ããã®ã§ãããããããªãæ¹ã¯ãã¡ããåç §ãã¦ãã ããã
ãã¡ã¤ã³æºå
ä½ããã®ã¬ã¸ã¹ãã©ã使ç¨ãã¦ãã¡ã¤ã³ãåå¾ãã¦ãã ããã
便å®ä¸ãåå¾ãããã¡ã¤ã³åãexample.comã¨ãã¾ãã
Cloudflare DNSã®è¨å®
Cloudflareã®DNSãã¹ãã£ã³ã°ãµã¼ãã¹ã使ãã¾ãã ç¡æããå©ç¨ã§ãã¾ãããã®æé ãDoxseyããã®è¨äºã«å«ã¾ãã¦ããã®ã§åç §ãã¦ãã ããã
ã¾ãã¢ã«ã¦ã³ãã®ãã¼ã ç»é¢ã«ç§»åãã+ Add a site ãã¿ã³ãããµã¤ããä½æãã¾ãã åæé ã§æºåãããã¡ã¤ã³åã使ã£ã¦ãã ããã
次ã«ä½æãããµã¤ãã®ããã·ã¥ãã¼ãã®DNS管çç»é¢ã«ç§»åãã¾ãã
Cloudflare DNSã§æ示ãããéãã«ãã¬ã¸ã¹ãã©ã§æå®ãã¦ããDNSãµã¼ããªã¹ããCloudflare DNSã®ãã®ã«ç½®ãæãã¦ãã ããããã®ç½®ãæãã®åæ ã«ã¯æéããããããããã¾ããã
ãã®æç¹ã§ã¯åãæ¢ããwww.example.comãexample.comã«ã¨ã¤ãªã¢ã¹ããããã®CNAMEã¬ã³ã¼ããä½ã£ã¦ããã¾ãããã
kubernetes-Cloudflare-sync ã®ãããã¤
ï¼ãã®æé ãDoxseyããã®è¨äºã«å«ã¾ãã¦ãã¾ãï¼
ããªã¨ã³ããã£ãã¤ã³ã¹ã¿ã³ã¹ã使ã£ã¦ããã¨Nodeã¯1æ¥ã«1度åä½æããã¾ãã ãã®éã«å¤é¨IPãå¤ãã£ã¦ãã¾ãã®ã§ããããããèªåçã«Cloudflare DNSã®Aã¬ã³ã¼ãã«åæããã«ã¹ã¿ã ã³ã³ããã¼ã©kubernetes-Cloudflare-syncãããã®ã§ãããã¤ãã¦ãã ããã ããã使ãã¨ãã¡ã¤ã³åããNodeã®å¤é¨IPãå¼ããç¶æ ã常ã«ç¶æããã¾ãã
ãããã¤ã«ã¯Cloudflare APIãæä½ããããã®APIãã¼ãå¿ è¦ã«ãªãã¾ãã詳ããã¯calebdoxsey/kubernetes-Cloudflare-syncã®READMEãã覧ãã ããã
Contourããããã¤
ããã¾ã§ã®æé ãè¡ãã¨ãã¡ã¤ã³åãããã¼ãå¤é¨IPãå¼ããããã«ãªã£ã¦ãã¾ããã ãã®ã¢ã¯ã»ã¹ãL7å¶å¾¡ããã³ã³ãã¼ãã³ããã¾ã ãããã¤ããã¦ãã¾ããã
Doxseyããã®è¨äºã§ã¯çã®Nginx DaemonSetã§L7å¶å¾¡ãã¦ããã®ã§ããã ããã¯ãã¾ã使ãåæãããããã¾ããã
ããã§çã®Nginx DaemonSetã¯ããã¦ãKubernetesãããå¤é¨ã¢ã¯ã»ã¹å¶å¾¡ããããã®Ingress Controllerãç«ã¦ã¾ãããã
ä»åã¯Ingress Controllerã«Contourãé¸ã³ã¾ãã Contourã¯Envoyãã¼ã¹ã®Ingress Controllerã§ãã ãã¦ã³ã¿ã¤ã ç¡ãã§è¨å®å¤æ´ãè¡ãããgRPCãæ±ãããshadow proxyããµãã¼ããã¦ãããªã©ã®é·æãããã¾ãã
ããããã¯Contourã®ãããã¤æ¹æ³ã説æãã¾ãããã¼ã¸ã§ã³v1.3.0ã使ç¨ãã¾ãã
Getting Startedã«å¾ãã¹ã¿ã³ãã¼ãã«ãããã¤ããã¨LoadBalancer Serviceã使ãã®ã§ããã GKEç°å¢ã§LoadBalancer Serviceãä½ã£ã¦ãã¾ãã¨åè¿°ã®èª²éãçºçãã¾ãã
ãããåé¿ããããã«Host Networkingãããã¤ãªãã·ã§ã³ãå©ç¨ãã¾ãã ããã¯Envoy DaemonSetããã¹ããããã¯ã¼ã¯ä¸ã«ãããã¤ããNodeã¸ã®80,443ã¢ã¯ã»ã¹ãEnvoyã§ãªãã¹ã³ããã¨ããæ¹å¼ã§ãã
contour/examples/contourã®ãããã§ã¹ã群ã«ä»¥ä¸ã®å¤æ´ãå ããapplyãã¦ãã ããã
- Envoyç¨Serviceã®
type: LoadBalancer
ã¨externalTrafficPolicy: Local
ã®æå®ãæ¶ã - Envoy Podã
hostNetwork: true
ã«ããdnsPolicy: ClusterFirstWithHostNet
ã«ãã - Contourã®
serve
ã³ãã³ãã«--envoy-service-http-port=80
ã¨--envoy-service-https-port=443
ã追å ãã
ããã¾ã§è¡ãã¨ãHTTPProxyã«ã¹ã¿ã ãªã½ã¼ã¹ã§ä»»æã®Serviceãã¤ã³ã¿ã¼ãããå ¬éã§ããããã«ãªãã¾ããHTTPProxyã¯Ingressãªã½ã¼ã¹ã®ç½®ãæãã¨ãªãã«ã¹ã¿ã ãªã½ã¼ã¹ã§ãã
Contourã¯Ingressãªã½ã¼ã¹ã解éã§ãã¾ãããIngressãªã½ã¼ã¹ãä½æããã¨GKE Ingress controllerãåä½ãã¦ãã¾ãäºæ ãèµ·ããããªãã®ã§HTTPProxyã使ãããã«ããã»ããè¯ãã§ãããã
Cert-managerãããã¤
ã©ãããªãHTTPSã使ç¨ãã¦ãµã¼ãã¹å ¬éãããã®ã§cert-managerããããã¤ãã¾ããããcert-managerã®ãããã¤ã¯ã¹ã¿ã³ãã¼ããªããæ¹ã§åé¡ããã¾ããã
ããã¾ã§ã®æ¡å ã«å¾ãã¨Cloudflare DNSã使ç¨ãã¦ããã¯ããªã®ã§ãCloudflareã§ACME DNS-01ãã£ã¬ã³ã¸ãããããã®Issuer/ClusterIssuerãä½æãã¾ããããCloudflareã®APIãã¼ã¯ã³ã使ç¨ãã¾ãã
HTTP-01ãã£ã¬ã³ã¸ãé¸ã¶ãã¨ãã§ãã¾ãããcert-managerã§HTTP-01ãã£ã¬ã³ã¸ãè¡ãã¨LoadBalancer Serviceãä¸æçã«ä½ããã¦ãã¾ãã®ã§ãDNS-01ãã£ã¬ã³ã¸ãå©ç¨ããã»ããè¯ãã§ãããã
ç¨æãããã¡ã¤ã³example.comã«ã¤ãã¦Certificateãªã½ã¼ã¹ãçºè¡ããä½æãããSecretãHTTPProxy.spec.tls.secretName
ã«ã»ããããã¨ã対象ã®ãµã¼ãã¹ãHTTPSã§å
¬éã§ãã¾ãã
ãããã§ã¹ãä¾ãè¼ãã¦ããã¾ãã
ClusterIssuer
apiVersion: cert-manager.io/v1alpha2 kind: ClusterIssuer metadata: name: cloudflare-prod spec: acme: email: [email protected] privateKeySecretRef: name: cloudflare-account-key server: https://acme-v02.api.letsencrypt.org/directory solvers: - dns01: cloudflare: apiTokenSecretRef: key: api-key name: cloudflare-api-key-secret email: [email protected]
Certificate
apiVersion: cert-manager.io/v1alpha2 kind: Certificate metadata: name: example.com spec: commonName: example.com dnsNames: - example.com issuerRef: kind: ClusterIssuer name: clouddns-prod secretName: example-com-prod-tls
HTTPProxy
apiVersion: projectcontour.io/v1 kind: HTTPProxy metadata: name: example spec: routes: - conditions: - prefix: / services: - name: frontend port: 3000 virtualhost: fqdn: example.com tls: secretName: example-com-prod-tls
ãµããã¡ã¤ã³è¿½å æ¹æ³
example.comã®ãµããã¡ã¤ã³ããã¨ãã°foo.example.comã追å ãããå ´åã®æé ã説æãã¾ãã
Cloudflare DNSã«CNAMEã¬ã³ã¼ãã追å ããfoo.example.comãexample.comã®ã¨ã¤ãªã¢ã¹ã¨ãªãããã«ãã¦ãã ããã
ãã¨ã¯example.comã®ã¨ãã¨åæ§ã«HTTPProxyãä½ãã ãã§ãã
ä»ãã¡ã¤ã³è¿½å æ¹æ³
example.com以å¤ã®ãã¡ã¤ã³ããã¨ãã°example2.comã追å ãããå ´åã®æé ã説æãã¾ãã
ã¾ãexample.comã®æã¨åæ§ãexample2.comãCloudflareã«site追å ããã¬ã¸ã¹ãã©ã®DNSãµã¼ããCloudflareã®ãã®ã«åãæ¿ãã¦ãã ããã
次ã«cloudflare-kubernetes-syncãæ°è¦ã§ãã1ã¤ãããã¤ãã¦ãã ããã ããããã¨example.comã¨example2.comã«åãAã¬ã³ã¼ããå²ãå½ã¦ããã¾ãã
ãã¨ã¯æ®éã«ãã§ã«ãããã¤æ¸ã¿ã®Contourã§HTTPProxyãä½ãã ãã§ãã
ã¾ã¨ã
GKEã§GCPãã¼ããã©ã³ãµã¨GKE Ingressã使ããã使ãåæãç¶æããã¾ã¾L7å¶å¾¡ããããã®æé ã説æãã¾ãããGKEã¨æ¸ãã¾ããããä»ã®KaaSã§ãåãæ°ããã¾ãã
ãã®è¨äºãæ¸ããå¾ãããä¸åº¦ãã®æé ãæåããåä½ç¢ºèªããã®ãé¢åããã¦ãã£ã¦ãªãã®ã§ã ãªã«ãæ¸ãæ¼ãããããããããã¾ããã 質åããã£ããæ¸ãã¦ãã ããã
ãã¨ãã®æé ã¯ãµã¼ãã¹ã®æ¿«ç¨ã£ã½ãæ°ãããªãã¯ãªãã§ããã ãã ã£ããæ¶ãã®ã§è¨ã£ã¦ãã ããã