Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

はてなリモートインターンシップ2022 Kubernetes 講義資料

Hatena
December 19, 2022

はてなリモートインターンシップ2022 Kubernetes 講義資料

https://hatena.co.jp/recruit/intern/2022

ハンズオンで利用した Kubernetes 環境は https://github.com/hatena/Hatena-Intern-Kubernetes-Microservice にあります。

Hatena

December 19, 2022
Tweet

More Decks by Hatena

Other Decks in Programming

Transcript

  1. עיםכؤ٤طػ k s ( AWS ECS) k s AWS EKS

    Google Cloud GKE AWS ECS 
  2. Cluster ˝ ُتذ٭ؿ٭غכ٠٭؜٭ؿ٭غך啶䡗׈׿׾ ˝ ُتذ٭ؿ٭غ ˝ ؤ٤عٞ٭ٜوٝ٭٤ ˝ ؠٚتذס畘杼؅䥵䎎 ˝

    قهٛشؠؠٚؗغךעُؾ٭ةغמ䬠❠׈׿׾ ˝ ٠٭؜٭ؿ٭غ ˝ ظ٭ذوٝ٭٤ ˝ ؤ٤طػ؅㲔车׌׾ג״סؤ٤مٖ٭طؔ٤ءٛ خ٭تס꥗ױ׽ ˝ 鎋碷ע䏲鳭 
  3. Service Pod ( ) 1 pod 2 pod pod IP

    ClusterIP ( ) NodePort ( ) LoadBalancer( ) etc 
  4. ُؼنؘتعס啶䡗 k8s ├── account │ ├── app.yaml │ ├── config

    │ │ └── schema.sql │ ├── db.yaml │ ├── kustomization.yaml │ ├── secret │ │ └── ecdsa-private.pem │ └── test.yaml ├── blog │ ├── app.yaml │ ├── config │ │ └── schema.sql │ ├── db.yaml │ ├── kustomization.yaml │ ├── secret │ │ └── account-ecdsa-public.pem │ └── test.yaml ├── kustomization.yaml ├── namespace.yaml ├── renderer-go │ ├── app.yaml │ └── kustomization.yaml └── system └── sa.yaml k8s account/blog/renderer-go kustomization.yaml kustomize 
  5. k s/blog/kustomization.yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - app.yaml -

    db.yaml - test.yaml secretGenerator: - name: blog-app-secret files: - secret/account-ecdsa-public.pem configMapGenerator: - name: blog-app-env-vars literals: # (snip) - name: blog-db-schema-config files: - config/schema.sql 
  6. 澬鏀 % make up 8080 % kubectl port-forward service/blog 8080:8080

    # ϩʔΧϧͷ8080ϙʔτ΁ ͷ௨৴Λblog service ͔Βෛՙ෼ࢄ͞Ε͍ͯΔpodͷ8080ϙʔτʹసૹ͢Δ Pod vscode terminal PORTS 8080 
  7. ظفشء # Podͷৄࡉ৘ใͷදࣔɻpod͕ىಈ͠ͳ͍৔߹͸ಛʹ"Events:"ཝʹ஫໨ % kubectl describe pod blog # ωʔϜεϖʔε্ʹ͋ΔϦιʔεͷ৘ใΛදࣔ

    % kubectl get all # ىಈ͍ͯ͠ΔPodͰγΣϧΛىಈ͢Δ % kubectl exec -it svc/account -c account !" /bin/sh ! ps blog ! wget -q -O - blog:8080 ! nslookup blog 
  8. ُؼنؘتعס鴑ⱶ % cp -R k8s/renderer-go k8s/renderer-ts % sed -i -e

    's/renderer-go/renderer-ts/g' k8s/renderer-ts/*.yaml k8s/renderer-go k8s/ renderer-ts renderer-go renderer-ts 
  9. ُؼنؘتعס稴꥗ ska old.yaml apiVersion: skaffold/v2beta5 kind: Config metadata: name: hatena-intern-2021

    build: artifacts: # (snip) - image: hatena-intern-2021-renderer-go context: services/renderer-go - image: hatena-intern-2021-renderer-ts # ! context: services/renderer-ts # ! local: # (snip) services/renderer-ts docker k s 
  10. ُؼنؘتعס稴꥗ k s/blog/kustomization.yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization # (snip) configMapGenerator:

    - name: blog-app-env-vars literals: - MODE=development - DATABASE_DSN=root@(blog-db:3306)/intern_2021_blog?time_zone=UTC&parseTime=true&loc=UTC - ACCOUNT_ADDR=account:50051 - RENDERER_ADDR=renderer-ts:50051 # ! - name: blog-test-env-vars # (snip) blog renderer-go renderer-ts 
  11. push push typescript use-renderer-ts-dekokun push ts renderer-ts % git switch

    -c use-renderer-ts-dekokun % git add k8s/ skaffold.yaml % git commit -m'rendererΛtypescript࣮૷ʹมߋ' % git push origin use-renderer-ts-dekokun 
  12. ظ٭ذي٭ت؅釳ַיײ׻ֹ ֽױׄؤ٭ػ٭նؓوٛآ٭ب٘٤ꝧ氦מ䏔מ玮חכ䓙ַױ׌ն % mysql -u root -h 127.0.0.1 -P 3306

    intern_2022_blog MySQL [intern_2022_blog]> show tables; +----------------------------+ | Tables_in_intern_2022_blog | +----------------------------+ | blogs | | entries | | sessions | | users | +----------------------------+ MySQL [intern_2022_blog]> select count(*) from blogs; +----------+ | count(*) | +----------+ | 0 | +----------+ 䫘禈ך׀םַ㕙⺬յَ٭عס鬇鴜ֿך׀יַםַ⺎耆䓪ֵֿ׽ױ׌ն♓┖סؤُ٤غךَ٭عنؚ٠٭غ׊יׂד׈ַ # ϙʔτͷసૹ % kubectl port-forward svc/blog-db 3306:3306 