使用Kubernetes部署一个服务

   说明:这里通过Kubernetes部署一个Eureka注册中心的服务,镜像使用制作好的并存在harbor镜像仓库中的镜像

 

 1 创建eureka190508.yaml文件

[chen@node0 app]$ vim eureka190508.yaml 

apiVersion: v1
kind: Service
metadata:
  name: eureka-service
  labels:
    app: eureka
spec:
  type: NodePort
  ports:
  - name: eureka-service-port
    port: 8761
apiVersion: v1
kind: Service
metadata:
  name: eureka-service
  labels:
    app: eureka
spec:
  type: NodePort
  ports:
  - name: eureka-service-port
    port: 8761
    targetPort: 8761
    protocol: TCP
  selector:
    app: eureka
    tier: eureka-tier
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: eureka-deployment
  labels:
    app: eureka
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: eureka
        tier: eureka-tier
    spec:
      containers:
      - image: smartsc.harbor.com/idss/hermes
        imagePullPolicy: Always
        name: eureka-container
        env:
        - name: PROFILE_ACTIVE
          value: docker
        - name: TZ
          value: Asia/Shanghai
        ports:
        - containerPort: 8761
          name: eureka-c-port
        resources:
          limits:
            memory: "500Mi"
            cpu: "500m"
          requests:
            memory: "500Mi"
            cpu: "250m"

2 部署eureka服务

[chen@node0 app]$ kubectl create -f eureka190508.yaml 
service/eureka-service created
deployment.apps/eureka-deployment created

3 查看服务

[chen@node0 app]$ kubectl get service |grep eureka
eureka-service                NodePort       10.102.68.223            8761:30461/TCP   51s

4 通过http://192.168.2.20:30461/访问服务(IP可以是集群中任意IP)

使用Kubernetes部署一个服务_第1张图片

你可能感兴趣的:(使用Kubernetes部署一个服务)