Search

Simple App

curl -L https://istio.io/downloadIstio | sh - cd istio-1.27.0 export PATH=$PWD/bin:$PATH istioctl version
Shell
복사
istioctl install --set profile=default -y
Shell
복사
Envoy 사이드카 Injection label 설정
kubectl label namespace default istio-injection=enabled
Shell
복사
# Nginx Service apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx service: nginx spec: ports: - port: 80 name: http selector: app: nginx --- apiVersion: v1 kind: ServiceAccount metadata: name: service-nginx labels: account: nginx --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx-v1 labels: app: nginx version: v1 spec: replicas: 1 selector: matchLabels: app: nginx version: v1 template: metadata: labels: app: nginx version: v1 spec: serviceAccountName: service-nginx containers: - name: nginx image: nginx:latest imagePullPolicy: IfNotPresent ports: - containerPort: 80 --- # Httpd Service apiVersion: v1 kind: Service metadata: name: httpdpage labels: app: httpdpage service: httpdpage spec: ports: - port: 80 name: http selector: app: httpdpage --- apiVersion: v1 kind: ServiceAccount metadata: name: service-httpdpage labels: account: httpdpage --- apiVersion: apps/v1 kind: Deployment metadata: name: httpdpage-v1 labels: app: httpdpage version: v1 spec: replicas: 1 selector: matchLabels: app: httpdpage version: v1 template: metadata: labels: app: httpdpage version: v1 spec: serviceAccountName: service-httpdpage containers: - name: httpd image: httpd:latest imagePullPolicy: IfNotPresent ports: - containerPort: 80 volumeMounts: - name: tmp mountPath: /tmp volumes: - name: tmp emptyDir: {}
YAML
복사
kubectl apply -f deploy.yaml
Shell
복사
apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: service-gateway spec: selector: istio: ingressgateway servers: - port: number: 80 name: http protocol: HTTP hosts: - "*" --- apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: httpdpage-nginx spec: hosts: - "*" gateways: - service-gateway http: - route: - destination: host: httpdpage port: number: 80 weight: 50 - destination: host: nginx port: number: 80 weight: 50
YAML
복사
kubectl apply -f gw-vs.yaml
Shell
복사
apiVersion: install.istio.io/v1alpha1 kind: IstioOperator spec: values: gateways: istio-ingressgateway: serviceAnnotations: service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
YAML
복사
istioctl upgrade -f nlb.yaml
Shell
복사
httpd, nginx만 출력되는 모습 확인 가능
특정 버전만 서비스 하기
VirtualService에서 subset을 지정하면 특정 버전만 서비스 할 수 있게 된다. 생성한 nginx는 총 2 가지 버전이 있는데 v2만 서비스 할 수 있게끔 구성하였다
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-v2 labels: app: nginx version: v2 spec: replicas: 1 selector: matchLabels: app: nginx version: v2 template: metadata: labels: app: nginx version: v2 spec: serviceAccountName: service-nginx containers: - name: nginx image: nginx:latest imagePullPolicy: IfNotPresent ports: - containerPort: 80 volumeMounts: - name: html-volume mountPath: /usr/share/nginx/html volumes: - name: html-volume configMap: name: nginx-config --- apiVersion: v1 kind: ConfigMap metadata: name: nginx-config data: index.html: | <html> <body> <h1>Hello, world!</h1> </body> </html>
YAML
복사
kubectl apply -f v2.yaml
Shell
복사
apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: httpdpage spec: host: httpdpage subsets: - name: v1 labels: version: v1 --- apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: nginx spec: host: nginx subsets: - name: v1 labels: version: v1 - name: v2 labels: version: v2
YAML
복사
kubectl apply -f destination-rule.yaml
Shell
복사
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: httpdpage-nginx spec: hosts: - "*" gateways: - service-gateway http: - route: - destination: host: httpdpage subset: v1 port: number: 80 weight: 50 - destination: host: nginx subset: v2 port: number: 80 weight: 50
YAML
복사
kubectl apply -f vs.yaml
Shell
복사
apiVersion: install.istio.io/v1alpha1 kind: IstioOperator spec: values: gateways: istio-ingressgateway: serviceAnnotations: service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
YAML
복사
istioctl upgrade -f nlb.yaml
Shell
복사
nlb 접근시 hello, world 페이지와 httpd 페이지만 표시되는걸 확인할 수 있다.