更新时间:2022-05-11 GMT+08:00
分享

使用示例

查看Node和Namespace

# kubectl get node
10.7.1.192                             Ready      <none>   104d   v1.15.11
10.7.122.60                            Ready      <none>   104d   v1.15.11
10.7.13.128                            Ready      <none>   84d    v1.15.11
196b3f9a-e097-4120-a8f8-8d2b172ea917   NotReady   edge     27d 

# kubectl get namespace
NAME                               STATUS   AGE
default                            Active   104d
e78acc02d9d141eda5ca8e88fa35f6f8   Active   104d
ief-system                         Active   104d
kube-node-lease                    Active   104d
kube-public                        Active   104d
kube-system                        Active   104d

创建Deployment

Deployment的描述方式与开源Kubernetes一致,Deployment部署到哪个边缘节点,由IEF的调度器选择。注意此种方式创建的应用不允许通过IEF界面进行更新。

建议使用指定节点方式部署Deployment,详见创建Deployment到指定节点

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
  namespace: e78acc02d9d141eda5ca8e88fa35    # namespace值为铂金版总览页面“命名空间”字段内容
  labels:
    app: nginx    # app值必须添加,且必须为metadata.name的值,即Deployment的名称
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: container-1
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
          hostPort: 8080
          protocol: TCP

创建Deployment到指定节点

部署Deployment到指定节点可以使用亲和性配置,根据节点ID将Deployment部署到指定节点。建议使用此种方式部署Deployment。注意此种方式创建的应用不允许通过IEF界面进行更新。

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
  namespace: e78acc02d9d141eda5ca8e88fa35f6f8    # namespace值为铂金版总览页面“命名空间”字段内容
  labels:
    app: nginx    # app值必须添加,且必须为metadata.name的值,即Deployment的名称
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      affinity:    
        nodeAffinity:      
          requiredDuringSchedulingIgnoredDuringExecution:        
            nodeSelectorTerms:          
            - matchExpressions:              
              - key: edgecloud.huawei.com/node_id    # key值必须为edgecloud.huawei.com/node_id
              operator: In
              values:                  
              - {node_id}    # 此处取值为边缘节点ID
      containers:
      - name: container-1
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
          hostPort: 8080
          protocol: TCP

创建Job

apiVersion: batch/v1
kind: Job
metadata:
  name: nginx-job
  namespace: e78acc02d9d141eda5ca8e88fa35f6f8    # namespace值为铂金版总览页面“命名空间”字段内容
  labels:
    job-name: nginx-job
spec:
  template:
    metadata:
      labels:
        job-name:  nginx-job
    spec:
      containers:
      - name: container-1
        image: swr.cn-north-7.myhuaweicloud.com/paas_ief_fwx310702/nginx:latest
        imagePullPolicy: IfNotPresent
      restartPolicy: Never

创建Service

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: e78acc02d9d141eda5ca8e88fa35f6f8    # namespace值为铂金版总览页面“命名空间”字段内容
spec:
  type: ClusterIP    # Service类型只支持ClusterIP类型
  ports:
  - port: 80
    name: http-nginx      # port名称需要符合istio要求,即<协议>-<名称>,如http-name
    targetPort: 30009
    protocol: TCP
  selector:
    app: nginx

创建完成后,可以通过“应用网格 > 服务列表”页面查询到Service的内部URL。

分享:

    相关文档

    相关产品

close