{"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

httpbin\u7de8<\/h2>\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
\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

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
\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

\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
\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

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
\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

\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

\nkubectl delete deployment httpbin<\/pre>\n

PHP\u7de8<\/h2>\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
\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

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
\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

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

\nkubectl port-forward $(kubectl get po | grep webapp-php | cut -d\" \" -f1) 8080:80<\/pre>\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>\n

Spring Boot\u7de8<\/h2>\n

\u4eca\u5ea6\u306fSpringBoot\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002
\nSpring Boot CLI<\/a> \u3092\u5229\u7528\u3057\u307e\u3059\u3002
\n\u5358\u4e00\u306egroovy\u30d5\u30a1\u30a4\u30eb\u3092\u66f8\u304f\u3060\u3051\u3067\u52d5\u4f5c\u3055\u305b\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u305f\u3081\u3001PHP\u3068\u540c\u3058\u3088\u3046\u306b\u3001Kubernetes\u306e\u30de\u30cb\u30d5\u30a7\u30b9\u30c8\u3060\u3051\u3067\u8d77\u52d5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u3002<\/p>\n

\n$ cat << EOS | kubectl apply -f -\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: webapp\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: webapp-spring\n  template:\n    metadata:\n      labels:\n        app: webapp-spring\n      annotations:\n        updated: \"$(date +%s)\"\n    spec:\n      containers:\n        - name: webapp-spring\n          image: rocko\/spring-boot-cli-docker\n          command: [\"\/root\/.sdkman\/candidates\/springboot\/current\/bin\/spring\"]\n          args: [\"run\", \"app.groovy\"]\n          workingDir: \/app\n          volumeMounts:\n            - name: config-volume\n              mountPath: \/app\n          readinessProbe:\n            httpGet:\n              path: \/actuator\/health\n              port: 8080\n      volumes:\n        - name: config-volume\n          configMap:\n            name: webapp-spring\n---\nkind: ConfigMap\napiVersion: v1\nmetadata:\n  name: webapp-spring\ndata:\n  app.groovy: |\n    @Grab(\"spring-boot-starter-actuator\")\n \n    @RestController\n    class WebApplication {\n        @RequestMapping(\"\/\")\n        String home() {\n            \"Hello World!\"\n        }\n    }\nEOS<\/pre>\n

\u8d77\u52d5\u3054\u3068\u306b\u4f9d\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304f\u308b\u306e\u3067\u8d77\u52d5\u304c\u3084\u305f\u3089\u9045\u3044\u3067\u3059\u304c\u3001Grab\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u30b3\u30fc\u30c9\u4e2d\u306b\u4f9d\u5b58\u95a2\u4fc2\u3092\u8a18\u8ff0\u3067\u304d\u308b\u305f\u3081\u30011\u30d5\u30a1\u30a4\u30eb\u3067\u5927\u6982\u306e\u51e6\u7406\u3092\u3053\u306a\u305b\u3066\u3057\u307e\u3044\u307e\u3059\u3002
\n\u7b46\u8005\u306f\u666e\u6bb5Java\u3084Kotlin\u3067SpringBoot\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u66f8\u3044\u3066\u3044\u308b\u305f\u3081\u3053\u3061\u3089\u3092\u3088\u304f\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n

\u307e\u3068\u3081<\/h2>\n

\u8981\u306f\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u8a00\u8a9e\u3067\u3042\u308c\u3070\u3001\u5fc5\u8981\u306a\u30d5\u30a1\u30a4\u30eb\u3092ConfigMap\u306b\u7a81\u3063\u8fbc\u3093\u3067\u30de\u30a6\u30f3\u30c8\u3059\u308c\u3070\u30ab\u30b9\u30bf\u30e0\u30a4\u30e1\u30fc\u30b8\u4f5c\u3089\u306a\u304f\u3066\u3082\u30a2\u30d7\u30ea\u8d77\u52d5\u3067\u304d\u308b\u3088\u306d\u3001\u3068\u3044\u3046\u8a71\u3067\u3057\u305f\u3002<\/p>\n

NodeJS+Express\u3084Ruby+Sinatra\u3042\u305f\u308a\u304c\u4f7f\u3048\u308b\u3068\u5feb\u9069\u306a\u6c17\u304c\u3057\u307e\u3059\u304c\u3001\u4f9d\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306e\u624b\u9593\u3092\u3046\u307e\u304f\u89e3\u6d88\u3059\u308b\u624b\u6bb5\u304c\u601d\u3044\u3064\u304b\u305a\u3001
\nApache\u3060\u3051\u3067\u305d\u308c\u306a\u308a\u306b\u52d5\u4f5c\u3057\u3066\u304f\u308c\u308bPHP\u3068\u3001\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e2d\u306b\u4f9d\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8a18\u8ff0\u3057\u3066\u3057\u307e\u3048\u308bSpringBootCLI\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n

P.S. Kubernetes\u306e\u3068\u3042\u308b\u6319\u52d5\u3092\u8abf\u67fb\u3057\u3066\u8a18\u4e8b\u306b\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u305f\u3082\u306e\u306e\u3001\u632b\u6298\u3057\u305f\u672b\u306b\u526f\u7523\u7269\u3092\u8a18\u4e8b\u306b\u3057\u305f\u306e\u306f\u5185\u7dd2\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u3053\u308c\u306f TECHSCORE Advent Calendar 2019\u306e11\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[332,18],"tags":[141,309],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/24537"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=24537"}],"version-history":[{"count":27,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/24537\/revisions"}],"predecessor-version":[{"id":24567,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/24537\/revisions\/24567"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=24537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=24537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=24537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}