Kubernetes上使用Weblogic Kubernetes Operator创建Weblogic Domain(使用NFS方式)

接着,Kubernetes上使用Weblogic Kubernetes Operator创建Weblogic Domain,这次使用Oracle Cloud Infrastructure(OCI)的File Storage作为Persistent Volume创建Weblogic Domain。

前提:

a,请先完成Kubernetes上使用Weblogic Kubernetes Operator创建Weblogic Domain的步骤1-6。

b,需要有Oracle Cloud Infrastructure(OCI)相关知识。

 

详细步骤:

1,获取weblogic kubernetes operator,进入到根目录。

git clone https://github.com/oracle/weblogic-kubernetes-operator.git
cd weblogic-kubernetes-operator

 2,创建weblogic domain的namespace

kubectl create namespace sample-domain2-ns

设置operator可以管理sample-domain2-ns

helm upgrade \
  --reuse-values \
  --set "domainNamespaces={sample-domain1-ns,sample-domain2-ns}" \
  --wait \
  sample-weblogic-operator \
  kubernetes/charts/weblogic-operator

设置traefik可以管理sample-domain2-ns

helm upgrade \
  --reuse-values \
  --set "kubernetes.namespaces={traefik,sample-domain1-ns,sample-domain2-ns}" \
  --wait \
  traefik-operator \
  stable/traefik

3,在Oracle Cloud Infrastructure(OCI)上创建FSS。

详细步骤:

1,在weblogic-kubernetes-operator的跟目录下,进入到创建pv和pvc的目录

cd kubernetes/samples/scripts/create-weblogic-domain-pv-pvc/

2,创建storage class。请修改mntTargetId。

cat < oci-fss.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  name: oci-storage-class
provisioner: oracle.com/oci-fss
parameters:
  # Insert mount target from the FSS here
  mntTargetId: ocid1.mounttarget.oc1.eu_frankfurt_1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
EOF

创建storage class

kubectl apply -f oci-fss.yaml

查看storage class

kubectl get storageclass

结果

NAME                PROVISIONER          AGE
oci-storage-class   oracle.com/oci-fss   11s

如果不是默认storage class,设置为默认storage class。(如果是,请直接跳到下一步)

kubectl patch storageclass oci-storage-class -p '{"metadata": {"annotations":                                                   {"storageclass.kubernetes.io/is-default-class":"true"}}}'

查看

kubectl get storageclass

结果(oci-storage-class后多了default)

NAME                          PROVISIONER          AGE
oci-storage-class (default)   oracle.com/oci-fss   6m43s

4,创建pv和pvc。

4-1,在FSS上创建domain目录(weblogic domain默认用opc用户安装,需要创建在FSS上创建一个目录,修改权限为777,否则会创建失败)

此处需要ssh连接到OCI上的同一VCN上的OKE VM或其他VM进行操作。

sudo mkdir -p /mnt/FileSystem-K8S
sudo mount 10.0.96.8:/FileSystem-K8S /mnt/FileSystem-K8S
sudo chmod 777 /mnt/FileSystem-K8S
sudo umount -v /mnt/FileSystem-K8S

4-2,修改pv-template.yaml

vi pv-template.yaml

修改以下内容

修改前

  storageClassName: %DOMAIN_UID%%SEPARATOR%%BASE_NAME%-storage-class

修改后

  storageClassName: oci-storage-class

追加下面内容

  (略)
  mountOptions:
  - nosuid
  (略)
    readOnly: false

修改后的完整内容

# Copyright 2018, Oracle Corporation and/or its affiliates.  All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: %DOMAIN_UID%%SEPARATOR%%BASE_NAME%-pv
  labels:
    weblogic.resourceVersion: domain-v2
    %DOMAIN_UID_LABEL_PREFIX%weblogic.domainUID: %DOMAIN_UID%
spec:
  storageClassName: oci-storage-class
  capacity:
    storage: %SAMPLE_STORAGE_SIZE%
  accessModes:
    - ReadWriteMany
  mountOptions:
  - nosuid
  # Valid values are Retain, Delete or Recycle
  persistentVolumeReclaimPolicy: %SAMPLE_STORAGE_RECLAIM_POLICY%
  %HOST_PATH_PREFIX%hostPath:
  %NFS_PREFIX%nfs:
    %NFS_PREFIX%server: %SAMPLE_STORAGE_NFS_SERVER%
    path: "%SAMPLE_STORAGE_PATH%"
    readOnly: false

4-3,修改pvc-template.yaml

vi pvc-template.yaml

修改以下内容

修改前

  storageClassName: %DOMAIN_UID%%SEPARATOR%%BASE_NAME%-storage-class

修改后

  storageClassName: oci-storage-class

追加下面内容

  volumeName: %DOMAIN_UID%%SEPARATOR%%BASE_NAME%-pv

修改后的完整内容

# Copyright 2018, Oracle Corporation and/or its affiliates.  All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: %DOMAIN_UID%%SEPARATOR%%BASE_NAME%-pvc
  namespace: %NAMESPACE%
  labels:
    weblogic.resourceVersion: domain-v2
    %DOMAIN_UID_LABEL_PREFIX%weblogic.domainUID: %DOMAIN_UID%
spec:
  storageClassName: oci-storage-class
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: %SAMPLE_STORAGE_SIZE%
  volumeName: %DOMAIN_UID%%SEPARATOR%%BASE_NAME%-pv

4-4,创建配置文件

拷贝templete文件

cp create-pv-pvc-inputs.yaml my-pv-pvc-inputs.yaml

修改my-pv-pvc-inputs.yaml

vi my-pv-pvc-inputs.yaml

修改前

domainUID:
namespace: default
weblogicDomainStorageType: HOST_PATH
#weblogicDomainStorageNFSServer: nfsServer
#weblogicDomainStoragePath: /scratch/k8s_dir

修改后

domainUID: sample-domain2
namespace: sample-domain2-ns
weblogicDomainStorageType: NFS
weblogicDomainStorageNFSServer: 10.0.96.8
weblogicDomainStoragePath: /FileSystem-K8S

4-5,创建pv和pvc

4-5-1,创建pv和pvc的配置文件

./create-pv-pvc.sh -i my-pv-pvc-inputs.yaml -o .

4-5-2,创建pv和pvc

kubectl apply -f ./pv-pvcs/sample-domain2-weblogic-sample-pv.yaml
kubectl apply -f ./pv-pvcs/sample-domain2-weblogic-sample-pvc.yaml

查看

kubectl get pv,pvc -n sample-domain2-ns

结果(STATUS为Bound )

NAME                                                                                                            CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                                  STORAGECLASS        REASON   AGE
persistentvolume/sample-domain2-weblogic-sample-pv                                                              10Gi       RWX            Retain           Bound    sample-domain2-ns/sample-domain2-weblogic-sample-pvc   oci-storage-class            54s

NAME                                                       STATUS   VOLUME                              CAPACITY   ACCESS MODES   STORAGECLASS        AGE
persistentvolumeclaim/sample-domain2-weblogic-sample-pvc   Bound    sample-domain2-weblogic-sample-pv   10Gi       RWX            oci-storage-class   36s

4-6,回到根目录

cd -

5,创建domain

5-1,创建docker secret

kubectl create secret docker-registry dockersecret \
  -n sample-domain2-ns \
  --docker-server=index.docker.io/v1/ \
  --docker-username=YOUR_USERNAME \
  --docker-password=YOUR_PASSWORD \
  --docker-email=YOUR_EMAIL

5-2,创建credentials

kubernetes/samples/scripts/create-weblogic-domain-credentials/create-weblogic-credentials.sh \
  -u weblogic -p welcome1 -n sample-domain2-ns -d sample-domain2

5-3,创建domain

拷贝templete文件

cd kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/
cp create-domain-inputs.yaml my-create-domain-inputs.yaml

修改my-create-domain-inputs.yaml

vi my-create-domain-inputs.yaml

修改前

domainUID: domain1
domainHome: /shared/domains/domain1
#imagePullSecretName:
weblogicCredentialsSecretName: domain1-weblogic-credentials
logHome: /shared/logs/domain1
exposeAdminT3Channel: false
exposeAdminNodePort: false
namespace: default
persistentVolumeClaimName: domain1-weblogic-sample-pvc

修改后

domainUID: sample-domain2
domainHome: /shared/domains/sample-domain2
imagePullSecretName: dockersecret
weblogicCredentialsSecretName: sample-domain2-weblogic-credentials
logHome: /shared/logs/sample-domain2
exposeAdminT3Channel: true
exposeAdminNodePort: true
namespace: sample-domain2-ns
persistentVolumeClaimName: sample-domain2-weblogic-sample-pvc
创建
./create-domain.sh -i my-create-domain-inputs.yaml -o . -e

回到根目录

cd -

6,发布testwebapp.war

访问weblogic控制台。输入用户名:weblogic 密码:welcome1。(创建credentials时设置的值)

http://:30701/console

发布testwebapp到cluster-1。(具体操作略)

7,创建ingress。

进入到创建ingress的路径

cd kubernetes/samples/charts/traefik/samples

拷贝template文件

cp path-routing.yaml testwebapp-path-routing.yaml

修改testwebapp-path-routing.yaml

vi testwebapp-path-routing.yaml

修改后的完整内容为

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: traefik-pathrouting-testwebapp
  namespace: sample-domain2-ns
  annotations:
    kubernetes.io/ingress.class: traefik
    ingress.kubernetes.io/rewrite-target: /testwebapp
    ingress.kubernetes.io/rule-type: PathPrefix
spec:
  rules:
  - host:
    http:
      paths:
      - path: /testwebapp
        backend:
          serviceName: sample-domain2-cluster-cluster-1
          servicePort: 8001

创建ingress

kubectl apply -f testwebapp-path-routing.yaml

8,检验

curl http://:30305/testwebapp/

作者先后2次执行的结果如下,

第1次



  
    

    
    Test WebApp
  
  


    
  • InetAddress: sample-domain2-managed-server2/10.244.2.98
  • InetAddress.hostname: sample-domain2-managed-server2
  • 第2次

    
    
      
        
    
        
        Test WebApp
      
      
    
    
        
  • InetAddress: sample-domain2-managed-server1/10.244.2.97
  • InetAddress.hostname: sample-domain2-managed-server1
  • 9,删除Domain

    helm delete --purge sample-domain2-ingress
    kubernetes/samples/scripts/delete-domain/delete-weblogic-domain-resources.sh -d sample-domain2

    10,删除Domain namespace

    helm upgrade \
      --reuse-values \
      --set "kubernetes.namespaces={traefik}" \
      --wait \
      traefik-operator \
      stable/traefik
    helm upgrade \
      --reuse-values \
      --set "domainNamespaces={}" \
      --wait \
      sample-weblogic-operator \
      kubernetes/charts/weblogic-operator
    kubectl delete namespace sample-domain1-ns

    11,删除weblogic operator

    helm delete --purge sample-weblogic-operator
    kubectl delete namespace sample-weblogic-operator-ns

    12,删除traefik operator

    helm delete --purge traefik-operator
    kubectl delete namespace traefik

    结尾!

     

    你可能感兴趣的:(Kubernetes)