iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 15
0
自我挑戰組

Cloud/SDN/SFC...菜鳥的學習筆記系列 第 15

Day15 開源專案-kube5gnfvo安裝

  • 分享至 

  • xImage
  •  

這是學長研究模擬5g元件可以在VM與容器混合佈署中可實驗,這屬於開源的專案,因此透過這次it鐵人賽來推廣如何使用,有興趣的可以看看。

開始佈署的前置

Kubernetes version為:v1.15.3
git的branch為v2.0.0
最少要兩台機器,一台當master一台當node。
node最低要五core

git clone https://github.com/free5gmano/kube5gnfvo.git

安裝套件

Multus

本身並不提供網路配置,是透過滿足其他 CNI 規範的 Plug-in 進行 container 的網路配置。

cd kube5gnfvo/example/
kubectl apply -f multus-daemonset-pre-1.16.yml

OpenvSwitch

apt install openvswitch-switch -y #安裝ovs
ovs-vsctl add-br br1 #新增bridge

OVS-CNI

cd kube5gnfvo/example/
kubectl apply -f ovs-cni.yaml

用CRD將CNI加入

(與上面啟用ovs的CNI無關)

cat <<EOF >./ovs-net-crd.yaml
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: ovs-net
  annotations:
    k8s.v1.cni.cncf.io/resourceName: ovs-cni.network.kubevirt.io/br1
spec:
  config: '{
      "cniVersion": "0.3.1",
      "type": "ovs",
      "bridge": "br1"
    }'
EOF
kubectl apply -f ovs-net-crd.yaml

Etcd Operator

注意,這部分如果master沒被汙染會Pending。

cd kube5gnfvo/example/etcd-cluster/rbac/
./create_role.sh
cd ..
kubectl apply -f deployment.yaml
(Please make sure that etcdclusters.etcd.database.coreos.com CRD in Kubernetes has been created)
kubectl apply -f ./

Metrics Server

cd kube5gnfvo/example/metrics-server/
kubectl apply -f ./

Node Exporter

可以取得node內的資訊

cd kube5gnfvo/example/
kubectl apply -f prom-node-exporter.yaml

KubeVirt

KubeVirt取得命令的方式

cd kube5gnfvo/example/kubevirt/
kubectl apply -f ./

遇到底下問題

error: unable to recognize "kubevirt-cr.yaml": no matches for kind "KubeVirt" in version "kubevirt.io/v1alpha3"

原因為kubevrit有沒還沒跑起來的 在執行一次kubectl apply -f .即可

Quick Start

cat <<EOF >./kube5gnfvo-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: kube5gnfvo-config
data:
  config: |
    ...
      'Here!'
    ...

EOF

kubectl apply -f kube5gnfvo-configmap.yaml

...
'Here!'
...
這部分改將 cat ~/.kube/config 取得的全部貼上去 如底下

cat <<EOF >./kube5gnfvo-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: kube5gnfvo-config
data:
  config: |
    apiVersion: v1
    clusters:
      - cluster:
          certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJd01EZ3lOekV6TlRVME5Gb1hEVE13TURneU5URXpOVFUwTkZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBUHkvClIzY2s0d3NBMlJQbEwzTTdyeTBqTzJhUEpQUWlKazRpVWFoMG5DcEdsS01zeUlnOHZ6bGs5eVRDNWx3QXZyRUwKeVhWUlNwbjQyNGVFVFZUS3M1VEZ5NHlSNlpFeEdsRzZ3TmVHc3BSZkNrelA3RDZNL3RMVmNUZFJqMFp2Q0owawpEZTRvcCtGMlNIVllKVm1Cb3A2cjUwTkkwWDBiKzRvY0V4WTREUEZpSGZ1cDR5c1pWc05XdGhFK205UDJXSGdjCittNS94VjJ0K0NLU21rUG1mZDFNMVh3ZXNjYW5rQlgwKy9PQ1hKbHRTZHNHRUdKY1ZoUE1SOXFlNEFrNU85MkcKSC9qT29RK21NcnBPeWFGbFdiWURoeGZLZVJNakNBTDlhU3dMa3VhWmZ2dTV6Mm44YTF6R0pJNUpaQWNoVGRZRwpWS3NhV2ZkRUFYdmF3bDRIVUE4Q0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFFd29heWhzYW56NTR3OFRxT2UwanZuQytLcFMKUkdXL2huQTJnbTU3ZXBmN2JMSU15UHN5WTlIOXhkVDJ4VjM1VXVqb2hpL3NTb3NmajcyU2N1QXZoL1Rkd2ZuQQoxNTU2ZFR4MFd6RUF4ekI4NGtxWlZWcTdFQXExbno1alFBRTN5eS9LMG1OMlRlelNIL3FHd2xaMUhqRnh2bUEyCmE2cmxvdkx3YXpWNWpORkwxRElGcjhONitHQ25sblZMU0VXM3ZWVHc4MzhTRnBNdXhXUE94OHdEbTA4bDlqYTYKdzdyemVDQTQ1eUpjMkxtQ0lUVkVYYlJUMTJLcHluaUlhWEVMa1cySmJ4eVFZa2ZGeUdKSVREOFZCSVo5ZFY1eApJLzBnS3d0Q0l6UFo2eG56UWx1NnorTUwrN0syVStaaU5HcmluV1lHY1NHNGd6R0hTOE5pNVZEdTV0MD0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
          server: https://10.0.0.68:6443
        name: kubernetes
    contexts:
      - context:
          cluster: kubernetes
          user: kubernetes-admin
        name: kubernetes-admin@kubernetes
    current-context: kubernetes-admin@kubernetes
    kind: Config
    preferences: {}
    users:
      - name: kubernetes-admin
        user:
          client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJYzNmcVp5ODRFZll3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TURBNE1qY3hNelUxTkRSYUZ3MHlNVEE0TWpjeE16VTFORGRhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlF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YldaMXhXWnJCRmlja0dEbjJ4Q1FWSjRCa2hFQnJhT1kxNTd1bUlNRHVWYU9GSFgKU0dkK0lidG1RRHoxdHc3TDE0TkZGVFB5M0ZDTlpzV0ZMdTVBZkhidFpZM2lpRVFocUp5RWlLOEZvT1IyRDBwUQpTamYrTldaL20ybzF0ZzNIRUN0dDBrOFVadnhialN5bFN1eSt0T0JLRmcwQTNSdFZDUUY2Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
EOF

Create kube5gnfvo ServiceAccount

cat <<EOF >./kube5gnfvo-sa.yaml
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: kube5gnfvo
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: kube5gnfvo
  namespace: default
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: kube5gnfvo
EOF

kubectl apply -f kube5gnfvo-sa.yaml

Deploy Mysql Database

cat <<EOF >./kube5gnfvo-mysql.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kube5gnfvo-mysql
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: kube5gnfvo-mysql
  template:
    metadata:
      labels:
        app: kube5gnfvo-mysql
    spec:
      containers:
      - image: mysql:5.6
        name: kube5gnfvo-mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: kube5gnfvo-mysql
          mountPath: /var/lib/mysql
        volumeMounts:
        - name: mysql-initdb
          mountPath: /docker-entrypoint-initdb.d
      volumes:
      - name: kube5gnfvo-mysql
        persistentVolumeClaim:
          claimName: kube5gnfvo-mysql
      volumes:
      - name: mysql-initdb
        configMap:
          name: mysql-initdb-config
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: kube5gnfvo-mysql
  labels:
    name: kube5gnfvo-mysql
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    type: DirectoryOrCreate
    path: /mnt/kube5gnfvo-mysql
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kube5gnfvo-mysql
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  selector:
    matchExpressions:
    - key: name
      operator: In
      values: ["kube5gnfvo-mysql"]
---
apiVersion: v1
kind: Service
metadata:
  name: kube5gnfvo-mysql
spec:
  ports:
  - port: 3306
  selector:
    app: kube5gnfvo-mysql
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-initdb-config
data:
  initdb.sql: |
    CREATE DATABASE kube5gnfvo;
EOF

kubectl apply -f kube5gnfvo-mysql.yaml

Deploy kube5gnfvo

cat <<EOF >./kube5gnfvo.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kube5gnfvo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kube5gnfvo
  template:
    metadata:
      labels:
        app: kube5gnfvo
    spec:
      serviceAccountName: kube5gnfvo
      containers:
      - image: free5gmano/kube5gnfvo-stage2
        name: kube5gnfvo
        env:
        - name: DATABASE_PASSWORD
          value: "password"
        - name: DATABASE_HOST
          value: "kube5gnfvo-mysql"
        - name: DATABASE_PORT
          value: "3306"
        command: ["/bin/sh","-c"]
        args: ['python3 manage.py migrate && python3 manage.py runserver 0:8000']
        ports:
        - containerPort: 8000
          name: kube5gnfvo
        volumeMounts:
        - name: kube5gnfvo-vnf-package
          mountPath: /root/NSD
          subPath: NSD
        - name: kube5gnfvo-vnf-package
          mountPath: /root/VnfPackage
          subPath: VnfPackage
        - name: kube-config
          mountPath: /root/config
          subPath: config
      volumes:
      - name: kube5gnfvo-vnf-package
        persistentVolumeClaim:
          claimName: kube5gnfvo-pvc
      - name: kube-config
        configMap:
          name: kube5gnfvo-config
          items:
          - key: config
            path: config
---
apiVersion: v1
kind: Service
metadata:
  name: kube5gnfvo
spec:
  type: NodePort
  ports:
  - port: 8000
    nodePort: 30888
  selector:
    app: kube5gnfvo
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kube5gnfvo-pvc
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  selector:
    matchExpressions:
    - key: name
      operator: In
      values: ["kube5gnfvo"]
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: kube5gnfvo-pv
  labels:
    name: kube5gnfvo
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    type: DirectoryOrCreate
    path: /mnt/kube5gnfvo
EOF

kubectl apply -f kube5gnfvo.yaml

到這裡就代表佈署部分好了,明天將講使用方式,其實安裝除了一些注意部分之外,其他都在github有介紹,有一些部分有相關套件的連結。


上一篇
Day14 菜鳥的SFC-使用API方式建立SFC
下一篇
Day16 開源專案-kube5gnfvo使用
系列文
Cloud/SDN/SFC...菜鳥的學習筆記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言