Search code examples
oracle-databasekubernetesoracle12ckubectlminikube

How to run remote image (Oracle Container Image) using kubectl in local machine?


I am using minikube and kubectl in my local machine. Now I need to run an oracle database with these. It can be any database.

Could you please let me know the way how I can run the oracle database on my local machine through minikube and kubectl?


Solution

  • Plan A:

    You can deploy oracle services in the form of submitting yaml files directly to k8s.

    Deploy

    The following is the definition code of Oracle deployment.

    This code consists of two parts, namely the deployment of Oracle deployment and its proxy service. The Oracle database deployed here is 11g r2, and the image used is mybook2019/oracle-ee-11g:v1.0. The two ports 1521 and 8080 are exposed through the NodePort mode, and the Oracle data is persisted through the nfs file system.

    oracle-service.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: oralce-svc
      labels:
        app: oralce
    spec:
      type: NodePort
      ports:
      - port: 1521
        targetPort: 1521
        name: oracle1521
      - port: 8080
        targetPort: 8080
        name: oralce8080
      selector:
        app: oralce
    

    oracle-deployment.yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: oralce
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: oralce
      strategy:
        type: Recreate
      template:
        metadata:
          labels:
            app: oralce
        spec:
          containers:
          - image: mybook2019/oracle-ee-11g:v1.0
            name: oralce
            - containerPort: 1521
              name: oralce1521
            - containerPort: 8080
              name: oralce8080
            volumeMounts:
            - name: oralce-data
              mountPath: /u01/app/oracle
          volumes:
          - name: oralce-data
            nfs:
              path: /home/sharenfs/oracle
              server: 192.168.8.132
    

    Through kubectl execute the following command to deploy the Oracle database in the Kubernetes cluster.

    $ kubectl create -f oracle-service.yaml
    $ kubectl create -f oracle-deployment.yaml
    

    After the deployment is complete, you can view the ports exposed by oracle through the following command (the ports here are 1521 and 32175)

    $ kubectl get svc
    

    svc

    Check

    For applications in the Kubernetes cluster, the relevant information for connecting to the database is as follows:

    hostname: oracle-svc.default
    port: 1521
    sid: EE
    service name: EE.oracle.docker
    username: system
    password: oracle
    

    For the machine where the oracle client is located, execute the following command to connect to the database.

    $ sqlplus system/oracle@//oracle-svc.kube-public:1521/EE.oracle.docker
    

    For applications outside the Kubernetes cluster, the relevant information used to connect to the database is as follows:

    hostname: 10.0.32.165
    port: 32175
    sid: EE
    service name: EE.oracle.docker
    username: system
    password: oracle
    

    For the machine where the oracle client is located, execute the following command to connect to the database.

    $ sqlplus system/oracle@//10.0.32.165:32175/EE.oracle.docker
    

    Plan B:

    Install by helm chart

    To install the chart with the release name db19c:

    Helm 3.x syntax

    $ helm install db19c oracle-db-1.0.0.tgz
    

    Helm 2.x syntax

    $ helm install --name db19c oracle-db-1.0.0.tgz
    

    The command deploys Oracle Database on the Kubernetes cluster in the default configuration. The configuration section lists the parameters that can be configured during installation.