{"id":24537,"date":"2019-12-11T08:00:10","date_gmt":"2019-12-10T23:00:10","guid":{"rendered":"https:\/\/www.techscore.com\/blog\/?p=24537"},"modified":"2019-12-11T12:46:59","modified_gmt":"2019-12-11T03:46:59","slug":"kubernetes%e3%81%ab%e4%bd%bf%e3%81%84%e6%8d%a8%e3%81%a6web%e3%82%a2%e3%83%97%e3%83%aa%e3%82%92%e7%ab%8b%e3%81%a6%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2019\/12\/11\/kubernetes%e3%81%ab%e4%bd%bf%e3%81%84%e6%8d%a8%e3%81%a6web%e3%82%a2%e3%83%97%e3%83%aa%e3%82%92%e7%ab%8b%e3%81%a6%e3%82%8b\/","title":{"rendered":"Kubernetes\u306b\u4f7f\u3044\u6368\u3066WEB\u30a2\u30d7\u30ea\u3092\u7acb\u3066\u308b"},"content":{"rendered":"
\u3053\u308c\u306f TECHSCORE Advent Calendar 2019<\/a>\u306e11\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n Kubernetes\u306b\u3068\u308a\u3042\u3048\u305aWEB\u30b5\u30fc\u30d0\u3092\u7acb\u3066\u305f\u3044\u6642\u3001\u3042\u308a\u307e\u305b\u3093\u304b\uff1f<\/p>\n \u5358\u306bHTTP\u3092\u53d7\u3051\u4ed8\u3051\u308b\u30b5\u30fc\u30d0\u304c\u6b32\u3057\u3044\u306e\u3067\u3042\u308c\u3070\u3001\u9069\u5f53\u306bApache\u3084nginx\u306e\u30a4\u30e1\u30fc\u30b8\u3092\u8d77\u52d5\u3059\u308c\u3070\u826f\u3044\u306e\u3067\u3059\u304c\u3001\u7b46\u8005\u306e\u5834\u5408\u3001\u30a8\u30c3\u30b8\u30b1\u30fc\u30b9\u306e\u8abf\u67fb\u306e\u305f\u3081\u306b\u3001\u51e6\u7406\u9045\u5ef6\u3055\u305b\u305f\u308a\u8ca0\u8377\u3092\u304b\u3051\u305f\u308a\u3001\u3082\u3046\u4e00\u637b\u308a\u5c0f\u7d30\u5de5\u3092\u5165\u308c\u305f\u3044\u30b1\u30fc\u30b9\u304c\u3088\u304f\u3042\u308a\u307e\u3059\u3002<\/p>\n \u81ea\u4f5c\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092Kubernetes\u3067\u52d5\u304b\u3059\u5834\u5408\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092Docker\u30a4\u30e1\u30fc\u30b8\u3067\u7528\u610f\u3059\u308b\u306e\u304c\u666e\u901a\u3067\u3059\u3002\u305f\u3063\u305f\u4e00\u884c\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u52d5\u304b\u3059\u305f\u3081\u306b\u3001Docker\u30d5\u30a1\u30a4\u30eb\u66f8\u3044\u3066\u3001\u30a4\u30e1\u30fc\u30b8\u3092\u30d3\u30eb\u30c9\u3057\u3066\u3001\u30ea\u30dd\u30b8\u30c8\u30ea\u7528\u610f\u3057\u3066\u3001\u30d7\u30c3\u30b7\u30e5\u3057\u3066\u2026\u2026 \u3082\u306e\u3050\u3055\u306a\u7b46\u8005\u306b\u306f\u8010\u3048\u96e3\u3044\u82e6\u75db\u3067\u3059\u3002<\/p>\n \u305d\u3093\u306a\u308f\u3051\u3067\u3001WEB\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092Docker\u30a4\u30e1\u30fc\u30b8\u3092\u69cb\u7bc9\u305b\u305a\u306b\u30b5\u30af\u30c3\u3068\u8d77\u52d5\u3055\u305b\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n \u81ea\u5206\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304f\u524d\u306b\u3001\u4ee3\u66ff\u624b\u6bb5\u304c\u306a\u3044\u304b\u691c\u8a0e\u3057\u3066\u307f\u308b\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002 httpbin\u306f\u300cA simple HTTP Request & Response Service.\u300d\u306e\u8aac\u660e\u3067 https:\/\/httpbin.org\/<\/a> \u3067\u30db\u30b9\u30c8\u3055\u308c\u3066\u3044\u308b\u30b5\u30fc\u30d3\u30b9\u3002 \u30ed\u30fc\u30ab\u30eb\u304b\u3089HTTP\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3060\u3051\u306a\u3089kubectl port-foward\u304c\u697d\u3067\u826f\u3044\u3067\u3059\u3002 http:\/\/localhost:8080\/ \u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001SwaggerUI\u306e\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u3069\u3093\u306aAPI\u304c\u3042\u308b\u306e\u304b\u898b\u3066\u304a\u304f\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002 \u8a18\u4e8b\u306e\u30bf\u30a4\u30c8\u30eb\u306b\u3042\u308b\u3088\u3046\u306b\u300c\u4f7f\u3044\u6368\u3066WEB\u30a2\u30d7\u30ea\u300d\u306a\u306e\u3067\u4e0d\u8981\u306b\u306a\u3063\u305f\u3089\u524a\u9664\u3059\u308b\u306e\u3092\u5fd8\u308c\u305a\u306b\u3002<\/p>\n httpbin\u306f\u4fbf\u5229\u3067\u3059\u304c\u3001\u305d\u308c\u3060\u3051\u3067\u3059\u3079\u3066\u306e\u8981\u671b\u306b\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002 httpbin\u306b\u6bd4\u3079\u3066\u304b\u306a\u308a\u8907\u96d1\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u30011\u30b3\u30de\u30f3\u30c9\u3067\u5b9f\u884c\u3067\u304d\u308b\u306e\u3067\u6211\u6162\u3057\u3066\u3044\u307e\u3059\u3002 port-forward\u3092\u8a2d\u5b9a\u3057http:\/\/localhost:8080 \u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u304a\u306a\u3058\u307f\u306ephpinfo\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n \u4f7f\u3044\u7d42\u308f\u3063\u3066\u524a\u9664\u3059\u308b\u969b\u306f kubectl apply -f - \u3092 kubectl delete -f - \u306b\u5909\u3048\u3066\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\nhttpbin\u7de8<\/h2>\n
\n\u4f8b\u3048\u3070\u300c\u6307\u5b9a\u6642\u9593sleep\u3092\u5165\u308c\u305f\u3044\u300d\u306a\u3093\u3066\u5834\u5408\u306fhttpbin\u304c\u89e3\u6c7a\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n
\n\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u30a4\u30f3\u30b9\u30da\u30af\u30b7\u30e7\u30f3\u3001Cookie\u767a\u884c\u3001\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3001\u30e9\u30f3\u30c0\u30e0\u30c7\u30fc\u30bf\u751f\u6210\u306a\u3069\u3001HTTP\u958b\u767a\u306b\u307e\u3064\u308f\u308b\u69d8\u3005\u306a\u30c4\u30fc\u30eb\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u307e\u3059\u3002
\nPython\u3067\u66f8\u304b\u308c\u305fOSS\u306a\u306e\u3067\u3001\u81ea\u524d\u3067\u8d77\u52d5\u3057\u3066\u304a\u304f\u3068\u8ca0\u8377\u3092\u639b\u3051\u305f\u3044\u6642\u306b\u3082\u6c17\u517c\u306d\u306a\u304f\u547c\u3073\u3060\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n$ kubectl create deployment --image kennethreitz\/httpbin httpbin<\/pre>\n
\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u9593\u3001kubectl\u3092\u5b9f\u884c\u3057\u305f\u30de\u30b7\u30f3\u306e8080\u30dd\u30fc\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068httpbin\u304c\u4f7f\u3048\u307e\u3059\u3002<\/p>\n\n$ kubectl port-forward $(kubectl get po | grep httpbin | cut -d\" \" -f1) 8080:80<\/pre>\n
\n\u4f8b\u3048\u3070\u4ee5\u4e0b\u306eURL\u3067\u30ec\u30b9\u30dd\u30f3\u30b9\u309210\u79d2\u9045\u5ef6\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n$ curl http:\/\/localhost:8080\/delay\/10\n{\n \"args\": {},\n \"data\": \"\",\n \"files\": {},\n \"form\": {},\n \"headers\": {\n \"Accept\": \"*\/*\",\n \"Host\": \"localhost:8080\",\n \"User-Agent\": \"curl\/7.29.0\"\n },\n \"origin\": \"127.0.0.1\",\n \"url\": \"http:\/\/localhost:8080\/delay\/10\"\n}<\/pre>\n
\nkubectl delete deployment httpbin<\/pre>\n
PHP\u7de8<\/h2>\n
\n\u30b5\u30af\u30c3\u3068\u66f8\u3044\u305f\u30b3\u30fc\u30c9\u3092\u52d5\u304b\u3059\u306e\u304c\u624b\u3063\u53d6\u308a\u65e9\u3044\u3053\u3068\u3082\u591a\u3044\u3067\u3059\u3002
\n\u305d\u3093\u306a\u6642\u306e\u305f\u3081\u3001Kubernetes\u306e\u30de\u30cb\u30d5\u30a7\u30b9\u30c8\u3060\u3051\u3067PHP\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u52d5\u4f5c\u3055\u305b\u3066\u307f\u307e\u3059\u3002<\/p>\n\n$ cat << EOS | kubectl apply -f -\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n name: webapp-php\nspec:\n selector:\n matchLabels:\n app: webapp-php\n template:\n metadata:\n labels:\n app: webapp-php\n annotations:\n updated: \"$(date +%s)\"\n spec:\n containers:\n - name: webapp-php\n image: php:7.3-apache\n volumeMounts:\n - name: config-volume\n mountPath: \/var\/www\/html\n volumes:\n - name: config-volume\n configMap:\n name: webapp-php\n---\nkind: ConfigMap\napiVersion: v1\nmetadata:\n name: webapp-php\ndata:\n index.php: |\n \nEOS<\/pre>\n
\nannotation\u306b\u65e5\u4ed8\u3092\u57cb\u3081\u8fbc\u3093\u3067\u3044\u308b\u306e\u306f\u30012\u56de\u4ee5\u964d\u306bapply\u3057\u305f\u969b\u306b\u65b0\u3057\u3044\u30b3\u30fc\u30c9\u304c\u53cd\u6620\u3055\u308c\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n\nkubectl port-forward $(kubectl get po | grep webapp-php | cut -d\" \" -f1) 8080:80<\/pre>\n
Spring Boot\u7de8<\/h2>\n