-
Notifications
You must be signed in to change notification settings - Fork 2
Install Istio and uEngine cloud k8s Setting
- 1 helm 설치
> helm install install/kubernetes/helm/istio --name istio --namespace istio-system
- 2 cli 설치
# 최신 버전 설치
> curl -L https://git.io/getLatestIstio | sh -
> cd istio-1.0.6
# 이전 버전 istio 설치
> curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.0.5 sh
> cd istio-1.0.5
# istioctl 을 사용할수 있도록 path 를 등록 한다.
> export PATH=$PWD/bin:$PATH
# istio 를 설치하는건 기본적으로 커스텀 리소스를 정의할수 있는 customresourcedefinition을 먼저 설치한다.
> kubectl apply -f install/kubernetes/helm/istio/templates/crds.yaml
# 그 후에 옵션별로 istio 를 인스톨 할수 있는데 그중에 TLS authentication between sidecars 할수있는 아래 옵션으로 설치한다
> kubectl apply -f install/kubernetes/istio-demo.yaml
## kubectl apply -f install/kubernetes/istio-demo-auth.yaml TLS 있는 버전은 이걸 설치
# istio 확인
> kubectl get po -n istio-system
> istioctl version
> kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/platform/kube/bookinfo.yaml)
위와같이 배포시 기존에 pod 의 ready 상태가 1/1 에서 2/2 로 변경되어 올라간다.
이는 하나의 pod 에 container 가 두개가 뜬다는 의미이다.
한개는 설정해 놓았던 docker image 를 가진 container 가 뜨고,
다른 하나는 istio-proxy 이름을 가진 container 가 sidecar 로 뜬다.
아래는 istio inject 된 pod 를 조회한 것이다.
container 를 확인해본다.
> kubectl get po serviceapi-5b475848b8-6hv7x -o yaml
...
containerStatuses:
- containerID: docker://dd7e6833633d6c0a725e3e4b8666e97ed607fa4ee87xxx
image: istio/proxyv2:1.0.5
name: istio-proxy
...
- containerID: docker://5418d1a084b41d32a6caf2058463a03cb84801a852xxxc
image: 979050235289.dkr.ecr.ap-northeast-2.amazonaws.com/uengine/serviceapi:latest
imageID: docker-pullable://xx.dkr.ecr.ap-northeast-
2.amazonaws.com/uengine/serviceapi@sha256:3b7d7028bbbc2c77e2a866161c33cb7aeddxx
...
...
# default 네임스페이스에 istio 로 자동 injection 을 하기 위하여 아래 스크립트를 실행한다.
> kubectl label namespace default istio-injection=enabled
# 확인
> kubectl get namespace -L istio-injection
NAME STATUS AGE ISTIO-INJECTION
default Active 14d enabled
ingress-nginx Active 2d
istio-system Active 1d disabled
# 삭제
> kubectl label namespace default istio-injection-
- 1 istio inject app
위의 설정에서 default namespace 에 auto inject 를 걸어놨으니 default 로 helm 배포하면 된다.
다만 requirements 에 있는 kafka 나 redis, db 등은 추후 설정을 하기로 하고 requirements.yaml 에 있는 내용을
모두 제거 한 뒤에 kafka 와 redis 는 inject 를 안하는 버전으로 설치를 하였다.
> kubectl get po
NAME READY STATUS RESTARTS AGE
deploy-monitor-5b5dcf579b-7sss7 2/2 Running 0 1d
my-redis-master-0 1/1 Running 0 9d
my-redis-slave-5c4755c6b6-2hdsm 1/1 Running 0 9d
pod-monitor-7ff695f77d-bcp6t 2/2 Running 0 1d
service-kube-controller-69f7876fdd-vnwxd 2/2 Running 0 1d
service-monitor-7f95cc64d6-82gjc 2/2 Running 0 1d
serviceapi-5b475848b8-6hv7x 2/2 Running 1 5h
serviceui-675b7fdd4f-bhpk6 2/2 Running 0 1d
- 2 egress 설정
istio 로 app 을 설치하게 되면 pod 에서 들어오고 나가는 모든 네트워크가 감시가 된다.
그리하여 외부로 호출을 할때는 호출을 가능케 해주는 egress 를 설정해야한다.
egress 는 istio 에서 kind: ServiceEntry 로 설정을 할 수 있다.
uEngine cloud k8s 프로젝트는 현재 2가지 외부로 나가는 경로가 존재한다.
첫번째로 DB 를 aws 의 RDS 를 사용한다. 두번째로 k8s 의 pod, deploy 등을 조회하기 위하여 kubernetes api 를 https 로 호출을 한다.
이 두가지에 대한 설정을 아래와 같이 해준다.
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: rds-service-entry
spec:
hosts:
- uengine.cxp0klyrcjfk.ap-northeast-2.rds.amazonaws.com # RDS 주소
ports:
- number: 3306
protocol: TCP
name: mysql
location: MESH_EXTERNAL # 외부 서비스를 Mash 방법
resolution: DNS # host 가 도메인 명이기때문에 DNS 로 설정을 하였고, ip 를 직접주는 static 등이 존재한다.
---
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: monitor-service
spec:
hosts:
- api.k8s.bzdvops.com
ports:
- number: 443
name: https
protocol: HTTPS
location: MESH_INTERNAL # 내부 서비스나 kubernetes 관련 서비스를 Mash
resolution: DNS
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bzdvops
spec:
hosts:
- api.k8s.bzdvops.com
tls:
- match:
- port: 443
sni_hosts:
- api.k8s.bzdvops.com
route:
- destination:
host: api.k8s.bzdvops.com
port:
number: 443
weight: 100 # 가중치 - 100%
-
3 kafka 연결 istio 를 auth 가 있는 버전으로 설치시 kafka 연결이 안된다.
x : (kubectl apply -f install/kubernetes/istio-demo-auth.yaml)
incubator/kafka 로 설치시 내부에 TLS 설정이 되어있어서 두개가 충돌이 나는지.. 정확히는 모르겠으나...
kafka 를 연결하려면 TLS 가 없는 버전으로 설치해야한다.
o : (kubectl apply -f install/kubernetes/istio-demo.yaml) -
4 Gateway 연결
kubernetes ingress 는 cluster 외부에서 오는 traffic 을 헨들링 하였으나,
Istio 에서는 Gateway와 VirtualService 를 함께 사용하여 traffic 을 Mesh 한다.
Gateway는 L4-L6 기능 만 구성하고 (예 : 노출 할 포트, TLS 구성), 그 후에
VirtualService를 바인딩하여 게이트웨이에 들어오는 TCP 트래픽과 HTTP 요청을 제어 할수 있다.
DestinationRule은 VirtualService 라우팅이 발생한 후 요청에 적용 할 정책 집합을 구성한다.
아래와 같이 설정을 한다.
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: echo-gateway
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*'
port:
name: http
number: 80
protocol: HTTP
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: serviceapi
spec:
gateways:
- echo-gateway
hosts:
- '*'
http:
- match:
- uri:
prefix: /
route:
- destination:
host: serviceapi
port:
number: 8080
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: serviceapi
spec:
host: serviceapi
trafficPolicy:
tls: {}
설명 :
ingressgateway 로 들어오는 모든 80 port 요청은 serviceapi:8080 으로 라우팅 된다.
위에서 보이는 DestinationRule 은 아무 처리도 안하는 Rule 이다.
- 5 service api 접속 url
kubernetes ingress 사용시에는 nginx ingress 를 사용하여 ingress 를 생성 후 해당 External-IP 로 접속을 하였었다.
Istio Gateway 사용시에는 istio-ingressgateway 의 External-IP 를 사용하면 된다.
> kubectl get svc -n istio-system -l app=istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP
istio-ingressgateway LoadBalancer 100.68.25.xx xxxxx-xxx.ap-northeast-2.elb.amazonaws.com