新钛云服已累计为您分享690篇技术干货
前言
Vault 是安全应用维护人员最喜欢的 hashcorp 产品之一 。Vault 是存储机密、证书、管理策略、加密数据等内容的安全工具。Vault 使用受信任的身份集中密码和控制访问权限,以此减少对静态、硬编码凭证的需求。它使用集中托管和受保护的加密密钥来动态和静态加密敏感数据,所有一切均可通过单个工作流和 API 实现。
Istio 非常重要的一个功能是能够锁定并且保护网格内的来往流量。本文的目的是基于 TLS 启动一个简单的 Web 应用程序,然后使用 Vault 生成对应的安全证书,从而保证 Istio 管理的服务安全。
简单点说,使用 TLS 时候,当您建立连接时,服务器会提供一个公钥,您可以使用此密钥对传输中的数据进行加密,一旦被目标服务器接收,数据将使用私钥解密。为了验证密钥是否有效,可以使用 CA(通常 CA 是付费服务),但我们可以通过 vault 创建一个自签名 CA)。
现在先让我们忽略 vault,让我们在系统上创建一个测试环境。为此使用 kind (https://kind.sigs.k8s.io/) 来快速创建一个测试环境。
用 kind 建立一个 kubernetes 集群
下载 kind 后,我们可以定义一个 kind 配置文件来启动 4 个 worker。我们还可以配置一些端口映射,以确保我们可以直接访问入口网关。
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30725
hostPort: 8080
listenAddress: "127.0.0.1"
protocol: TCP
- containerPort: 32652
hostPort: 8443
listenAddress: "127.0.0.1"
protocol: TCP
- role: worker
- role: worker
- role: worker
- role: worker
使用 kind 来创建我们的集群
kind create cluster --name chris --config ~/kube.cfg
节点已启动
kubectl get nodes
NAME STATUS ROLES AGE VERSION
chris-control-plane Ready control-plane 21h v1.24.0
chris-worker Ready <none> 21h v1.24.0
chris-worker2 Ready <none> 21h v1.24.0
chris-worker3 Ready <none> 21h v1.24.0
chris-worker4 Ready <none> 21h v1.24.0
使用istioctl (https://github.com/istio/istio/releases) 命令安装 istio 。首先让我们定义一下配置内容。因为我们在本地运行,所以我们降低了一些资源要求。
---
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
namespace: istio-system
name: installed-state
spec:
components:
ingressGateways:
-
enabled: true
name: istio-ingressgateway
namespace: istio-system
pilot:
k8s:
hpaSpec:
maxReplicas: 2
minReplicas: 1
resources:
requests:
cpu: 512m
memory: 512Mi
profile: default
values:
global:
istioNamespace: istio-system
安装 istio
istioctl manifest install -f ~/istio.cfg
删除默认类型的 istio-ingressgateway 的 service。
kubectl delete svc istio-ingressgateway -n istio-system
创建一个 NodePort 服务,从而实现从节点端口访问 istio-ingressgateway 。
apiVersion: v1
kind: Service
metadata:
labels:
app: istio-ingressgateway
istio: ingressgateway
name: istio-ingressgateway
namespace: istio-system
spec:
type: NodePort
ports:
- name: http
nodePort: 30725
port: 8080
protocol: TCP
targetPort: 8080
- name: https
nodePort: 32652
port: 443
protocol: TCP
targetPort: 8443
selector:
app: istio-ingressgateway
应用一下
<