9.3. 验证部署
创建一个新项目
$ oc new-project hello-world
部署 hello world 应用:
$ oc new-app -n hello-world --image=docker.io/openshift/hello-openshift
为 AWS 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 Load Balancer Operator 部署 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
curl AWS ALB Ingress 端点,以验证 hello world 应用程序是否可访问:
注意AWS ALB 置备需要几分钟。如果您收到显示
curl: (6) Could not resolve host
的错误,请等待再试一次。$ INGRESS=$(oc -n hello-world get ingress hello-openshift-alb \ -o jsonpath='{.status.loadBalancer.ingress[0].hostname}') $ curl "http://${INGRESS}"
输出示例
Hello OpenShift!
为您的 hello world 应用程序部署 AWS 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
测试 AWS 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!