那麼這幾天所要介紹的kube5gnfvo因為此專案為free5gmano的子專案,所以就更像是將這些步驟一一拆開來做為API方式 讓人使用,那麼這幾天介紹此專案就可以讓人更了解要如何去實踐一個NS的步驟了。
那麼今天就來做一個kube5gnfvo的環境建置吧!
有些部分在前幾天有介紹的安裝方式,在今天我還會再重複一次,這樣就不用再翻回之前的安裝介紹了:D
kubernetes v1.18
ubuntu 20.04
git clone https://github.com/free5gmano/kube5gnfvo.git
cd kube5gnfvo/example/
kubectl apply -f multus-daemonset.yml
apt install openvswitch-switch -y
ovs-vsctl add-br br1
cd kube5gnfvo/example/
kubectl apply -f ovs-cni.yaml
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
這是由於kube5gnfvo會使用到etcd做存取,因此需要做安裝的動作
cd 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 ./
cd ../metrics-server/
kubectl apply -f ./
cd ..
kubectl apply -f prom-node-exporter.yaml
由於kube5gnfvo有支援使用kubevirt做安裝虛擬機,因此需要安裝。
cd kubevirt/
kubectl apply -f kubevirt-operator.yaml
# 這裡注意要先等operator建立起來再跑底下的cr,因為cr是kubevirt的CRD
kubectl apply -f kubevirt-cr.yaml
到這裡就是安裝完環境了,那麼我們開始建立kube5gnfvo吧
需要先將kubernetes的內容api config放置進來
cat ~/.kube/config
請注意,內容要放在config的下一層
cat <<EOF >./kube5gnfvo-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: kube5gnfvo-config
data:
config: |
<cat ~/.kube/config 後取得的所有內容>
EOF
kubectl apply -f kube5gnfvo-configmap.yaml
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
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
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
那麼到這裡就完成了,明天將會進行解析其使用的TOSCA Temple的部分,明天見:D