如何获得一个Kubernetes Pod来访问一个Oracle数据库?

时间:2018-08-29 19:56:55

标签: oracle kubernetes external kubernetes-networkpolicy

我一直在尝试使用kuberentes容器来访问数据库中的外部oracle。当Pod旋转时,与访问外部oracle数据库相关的PID会挂起并且不会超时。

这是我的Yaml:

apiVersion: batch/v1
kind: Job
metadata:
  name: neuron-oracle-producer-clinrpt
  namespace: pubsub
spec:
  template:
    metadata:
      labels:
        app: neuron-oracle-producer-clinrpt
    spec:
      restartPolicy: Never
      hostNetwork: true
      containers:
      - name: neuron-oracle-producer-clinrpt
        image: ndtregistry.azurecr.io/neuron-oracle-producer-clinrpt:latest
        imagePullPolicy: Always
        command: ["neuron-oracle-producer-clinrpt"]
        ports:
          - containerPort: 1521
            hostPort: 1521
        env:
        - name: ORA_USERNAME
          valueFrom:
            secretKeyRef:
              name: clinrpt
              key: username
        - name: ORA_PASSWORD
          valueFrom:
            secretKeyRef:
              name: clinrpt
              key: password
        - name: QUEUE_HOST
          value: "broker.kafka.svc.cluster.local"
        - name: QUEUE_PORT
          value: "9092"
        - name: QUEUE_CATEGORIES
          value: "json"
        - name: LOG_FILE
          value: "/var/log/neuron-oracle-producer-clinrpt.txt"
        - name: MESSAGE_SOURCE
          value: "ClinRpt"
        - name: MESSAGE_FORMAT
          value: "json"
        - name: DEBUG
          value: "TRUE"
        resources:
          requests:
            cpu: 500m
            memory: 1Gi
          limits:
            cpu: 500m
            memory: 1Gi
        volumeMounts:
        - name: logs
          mountPath: /var/log/producer
      imagePullSecrets:
      - name: azureregistry
      volumes:
      - name: logs
        emptyDir: {}

如何使我的Pod访问外部Oracle数据库?

1 个答案:

答案 0 :(得分:1)

这可能为时已晚,但是您可能要尝试添加:

  1. 一项k8s服务,可让广告连播知道要调用的数据库
  2. 将外部IP地址映射到服务的k8s端点

理论价格:默认情况下,K8s搜索本地服务。这将创建一个具有到外部服务URI的映射的本地服务。更多信息:https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-mapping-external-services