1.3. 验证 Operator 安装
部署基本示例应用程序并创建入口和负载均衡服务,以确认 AWS Load Balancer Operator 和 Controller 是否已正确部署。
流程
创建一个新项目
$ oc new-project hello-world根据
hello-openshift镜像创建一个新的hello-world应用程序:$ oc new-app -n hello-world --image=docker.io/openshift/hello-openshift为 AWS Application Load Balancer (ALB)配置
NodePort服务以连接:$ cat << EOF | oc apply -f - apiVersion: v1 kind: Service metadata: name: hello-openshift-nodeport namespace: hello-world spec: ports: - port: 80 targetPort: 8080 protocol: TCP type: NodePort selector: deployment: hello-openshift EOF为应用程序部署 AWS ALB:
$ cat << EOF | oc apply -f - apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: hello-openshift-alb namespace: hello-world annotations: alb.ingress.kubernetes.io/scheme: internet-facing spec: ingressClassName: alb rules: - http: paths: - path: / pathType: Exact backend: service: name: hello-openshift-nodeport port: number: 80 EOF测试对应用程序的 AWS ALB 端点的访问:
注意ALB 置备需要几分钟时间。如果您收到一个错误,显示
curl: (6) Could not resolve host,请等待并重试。$ ALB_INGRESS=$(oc -n hello-world get ingress hello-openshift-alb \ -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')$ curl "http://${ALB_INGRESS}"输出示例
Hello OpenShift!为应用程序部署 AWS Network Load Balancer (NLB):
$ cat << EOF | oc apply -f - apiVersion: v1 kind: Service metadata: name: hello-openshift-nlb namespace: hello-world annotations: service.beta.kubernetes.io/aws-load-balancer-type: external service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: instance service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing spec: ports: - port: 80 targetPort: 8080 protocol: TCP type: LoadBalancer selector: deployment: hello-openshift EOF测试对应用程序的 NLB 端点的访问:
注意NLB 置备需要几分钟时间。如果您收到一个错误,显示
curl: (6) Could not resolve host,请等待并重试。$ NLB=$(oc -n hello-world get service hello-openshift-nlb \ -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')$ curl "http://${NLB}"预期输出显示
Hello OpenShift!。现在,您可以删除示例应用程序和
hello-world命名空间中的所有资源。$ oc delete project hello-world