概要
- k8sテスト環境構築
Istio インストール
構築目次
環境
- Rancher: v2.6.3
- kubernetes(Client): v1.22.4
- kubernetes(Server): v1.22.4
- Istio: v1.12.1
インストール
1. Istioctl(コマンドラインツール)をダウンロード
- 作業場所: ClientPC
- Istio Release Page
https://github.com/istio/istio/releases - ファイル説明
istio-x.x.x-linux-amd64.tar.gz: istioctlコマンド + istioサンプル
istioctl-x.x.x-linux-amd64.tar.gz: istioctlコマンドのみ
$ wget https://github.com/istio/istio/releases/download/1.12.1/istioctl-1.12.1-linux-amd64.tar.gz
$ tar xvf istioctl-1.12.1-linux-amd64.tar.gz
$ sudo mv istioctl /usr/local/bin/
## version 確認 ##
$ istioctl version
no running Istio pods in "istio-system"
1.12.1
2. Istio インストール
※Istioのインストール方法にはコマンド、helm、operatorなどによるインストールがある。
→ ここではコマンドでインストール。
-
Istio Install Page
https://istio.io/latest/docs/setup/install/istioctl/ -
設定ファイル作成
※HPAを無効、Replicaを「2」に設定
※設定・オプションは以下参照
https://istio.io/latest/docs/reference/config/istio.operator.v1alpha1/
https://istio.io/v1.5/docs/reference/config/installation-options/
config.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
components:
pilot:
k8s:
replicaCount: 2
ingressGateways:
- name: istio-ingressgateway
k8s:
replicaCount: 2
values:
gateways:
istio-ingressgateway:
autoscaleEnabled: false
pilot:
autoscaleEnabled: false
-
Istioのビルトインprofileを指定
※各profile 詳細説明
https://istio.io/latest/docs/setup/additional-setup/config-profiles/ -
インストール
## Default profile・Default 設定でインストールする場合
$ istioctl install
## profileを指定する場合
$ istioctl install --set profile=<profile名>
## 上記で作成した設定ファイル(config.yaml)で設定をカスタマイズする場合
$ istioctl install -f config.yaml
## インストール後、確認
$ istioctl verify-install
## 設定確認
$ kubectl -n istio-system get IstioOperator installed-state -o=json
## リソース確認
$ kubectl -n istio-system get all
NAME READY STATUS RESTARTS AGE
pod/istio-ingressgateway-8c48d875-798r5 1/1 Running 0 11m
pod/istio-ingressgateway-8c48d875-86xtb 1/1 Running 0 68m
pod/istiod-58d79b7bff-62l8k 1/1 Running 0 68m
pod/istiod-58d79b7bff-c2gj8 1/1 Running 0 11m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/istio-ingressgateway LoadBalancer 10.43.141.17 192.168.245.112 15021:31809/TCP,80:32237/TCP,443:32558/TCP 68m
service/istiod ClusterIP 10.43.140.26 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 68m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/istio-ingressgateway 2/2 2 2 68m
deployment.apps/istiod 2/2 2 2 68m
NAME DESIRED CURRENT READY AGE
replicaset.apps/istio-ingressgateway-8c48d875 2 2 2 68m
replicaset.apps/istiod-58d79b7bff 2 2 2 68m
3. Istio用prometheus, grafana, kiali インストール
- Integration Configuration Page
https://istio.io/latest/docs/ops/integrations/
## prometheus インストール ##
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.12/samples/addons/prometheus.yaml
## grafana インストール ##
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.12/samples/addons/grafana.yaml
## kiali インストール ##
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.12/samples/addons/kiali.yaml
## pod 確認 ##
$ kubectl -n istio-system get pod
NAME READY STATUS RESTARTS AGE
grafana-6ccd56f4b6-qd8sm 1/1 Running 0 77s
..........
kiali-79b86ff5bc-cjpww 1/1 Running 0 67s
prometheus-64fd8ccd65-mmzdt 2/2 Running 0 87s
- prometheus 実行確認
$ istioctl dashboard prometheus
- grafana 実行確認
$ istioctl dashboard grafana
- kiali 実行確認
$ istioctl dashboard kiali
動作確認
- Istio-Injection設定
サンプルPodを作成するnamespaceにIstio-Injection設定を追加
## Istioテスト用Namespace作成 ##
$ kubectl create ns istio-test
## 「istio-test」namespaceに「istio-injection=enabled」ラベルを追加 ##
$ kubectl label ns istio-test istio-injection=enabled --overwrite
## 確認 ##
$ kubectl get ns istio-test -L istio-injection
NAME STATUS AGE ISTIO-INJECTION
..........
istio-test Active 6m enabled
..........
※テスト後、Namespaceからラベルを削除する場合は以下実行
$ kubectl label ns istio-test istio-injection-
- マニフェスト作成
istio-test.yaml
---
# Service作成
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
namespace: istio-test
spec:
selector:
app: nginx
ports:
- name: http
port: 8080
targetPort: 80
---
# Pod作成
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: istio-test
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.21.4
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
---
# Gateway作成
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: test-gateway
namespace: istio-test
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "nginx-istio.test.local"
---
# VirtualService作成
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: test-virtualservice
namespace: istio-test
spec:
gateways:
- test-gateway
hosts:
- "nginx-istio.test.local"
http:
- route:
- destination:
host: nginx-svc
port:
number: 8080
$ kubectl apply -f istio-test.yaml
## 確認 ##
$ kubectl get pod -n istio-test
NAME READY STATUS RESTARTS AGE
nginx 2/2 Running 0 20s
$ kubectl -n istio-test get pod nginx -o jsonpath='{.spec.containers[*].name}'
nginx istio-proxy
- ingressgatewayの
EXTERNAL-IP
を確認
※本環境ではMetalLBを利用し、EXTERNAL-IPへIP自動割振
※インストールは[ここ] (https://qiita.com/prodigy413/items/3a24ff85819dc5eafe25)参照
$ kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
..........
istio-ingressgateway LoadBalancer 10.43.141.17 192.168.245.112 15021:31809/TCP,80:32237/TCP,443:32558/TCP 20h
..........
- hosts 設定追加
ingressgatewayのEXTERNAL-IP
とVirtualServiceで設定したhostを追加
$ cat /etc/hosts
........
192.168.245.112 istio-nginx.test.local
........
- 接続確認
$ curl -I http://istio-nginx.test.local
HTTP/1.1 200 OK
.........
.........