Mac 용 Docker [Edge]에서 Kubernetes를 사용해보십시오.
12918 단어 php-fpmnginx도커kubernetes
Mac 용 Docker [Edge]에서 Kubernetes를 사용해보십시오.
설치
Mac용 Docker[Edge]을 설치합니다.
$ brew install kubernetes-helm
$ docker -v
Docker version 18.03.0-ce-rc4, build fbedb97
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.2", GitCommit:"5fa2db2bd46ac79e5e00a4e6ed24191080aa463b", GitTreeState:"clean", BuildDate:"2018-01-18T10:09:24Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.2", GitCommit:"5fa2db2bd46ac79e5e00a4e6ed24191080aa463b", GitTreeState:"clean", BuildDate:"2018-01-18T09:42:01Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
$ helm version
Client: &version.Version{SemVer:"v2.8.1", GitCommit:"6af75a8fd72e2aa18a2b278cfe5c7a1c5feca7f2", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.8.1", GitCommit:"6af75a8fd72e2aa18a2b278cfe5c7a1c5feca7f2", GitTreeState:"clean"}
Kubernetes란?
신청
이번에는 Nginx + PHP-FPM 7.1 웹 애플리케이션을 구축합니다.
Dockerfile
Dockerfile
FROM nginx:1.13.8-alpine
ADD conf/nginx.conf /etc/nginx/nginx.conf
nginx.conf
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type text/html;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
root /docker/app/;
location / {
index index.php;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
Dockerfile
FROM php:7.1-fpm-alpine
Docker 컨테이너 빌드
$ docker build -t sample/nginx:1.0 docker/nginx
$ docker build -t sample/php:1.0 docker/php-fpm
Pods
Deployment
deployment.yml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: sample-k8s
spec:
replicas: 1
template:
metadata:
labels:
name: sample-k8s
spec:
containers:
- name: sample-nginx
image: "sample/nginx:1.0"
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
volumeMounts:
- name: web-root
mountPath: /docker
- name: sample-php
image: "sample/php:1.0"
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9000
volumeMounts:
- name: web-root
mountPath: /docker
volumes:
- name: web-root
hostPath:
path: /Users/moritake/go/src/github.com/mediba-moritake/sample-kubernetes
서비스
service.yml
apiVersion: v1
kind: Service
metadata:
name: sample-k8s
spec:
type: NodePort
# type: LoadBalancer
selector:
name: sample-k8s
ports:
- port: 8080
protocol: TCP
targetPort: 8080
Ingress
ingress.yml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: sample-k8s
annotations:
kubernetes.io/ingress.class: nginx
spec:
backend:
serviceName: sample-k8s
servicePort: 8080
Ingress Controller
$ helm install stable/nginx-ingress
Deployment, Service, Ingress 만들기
$ kubectl create -f deployment.yml -f service.yml -f ingress.yml
PHP 애플리케이션
index.php<?php
echo 'Hello k8s!';
동작 확인
$ curl localhost
Hello k8s!
요약
$ kubectl create -f deployment.yml -f service.yml -f ingress.yml
index.php
<?php
echo 'Hello k8s!';
동작 확인
$ curl localhost
Hello k8s!
요약
$ curl localhost
Hello k8s!
Mac용 Docker[Edge]에서 Kubernetes를 사용해 보았습니다.
type: LoadBalancer
와 같이 설정합시다. Amazon EKS (현재는 미리보기)를 빨리 사용하고 싶습니다.
소스 코드
참고(자주 사용하는 명령)
$ kubectl get pods
$ kubectl get service
$ kubectl get ingress
$ kubectl describe pods
$ kubectl describe service
$ kubectl describe ingress
$ kubectl log #{pod名} -c #{コンテナ名}
$ kubectl log sample-k8s-xxxxxxxxxx-yyyyy -c sample-nginx
$ kubectl exec -it #{pod名} -c #{コンテナ名} ash
$ kubectl exec -it sample-k8s-xxxxxxxxxx-yyyyy -c sample-nginx ash
$ kubectl exec -it sample-k8s-xxxxxxxxxx-yyyyy -c sample-php ash
$ kubectl exec #{pod名} -c #{コンテナ名} -- #{コマンド}
$ kubectl exec sample-k8s-xxxxxxxxxx-yyyyy -c sample-nginx -- nginx -v
$ kubectl exec sample-k8s-77596b46b5-ggvg4 -c sample-php -- php -v
Reference
이 문제에 관하여(Mac 용 Docker [Edge]에서 Kubernetes를 사용해보십시오.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/y-moritake/items/6cce164c3bda317c32b8텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)