k8s安装eureka

2022-09-19 10:32:36 浏览数 (1)

# 1.编辑k8s-eureka-prod.yml

点击查看

代码语言:javascript复制
apiVersion: v1
kind: ConfigMap
metadata:
  name: eureka-cm
data:
  # if you want to deploy n instances of eureka cluster, 
  # you should set eureka_service_address: http://eureka-0.eureka:8761/eureka,...,http://eureka-(n-1).eureka:8761/eureka
  eureka_service_address: http://eureka-0.eureka:8761/eureka,http://eureka-1.eureka:8761/eureka,http://eureka-2.eureka:8761/eureka
---
apiVersion: v1
kind: Service
metadata:
  name: eureka-np
  labels:
    app: eureka
spec:
  type: NodePort
  ports:
  - port: 8761
    nodePort: 28600
    name: eureka
  selector:
    app: eureka
---
apiVersion: v1
kind: Service
metadata:
  name: eureka
  labels:
    app: eureka
spec:
  clusterIP: None
  ports:
  - port: 8761
    name: eureka
  selector:
    app: eureka
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: eureka
spec:
  serviceName: 'eureka'
  # n instances
  replicas: 3
  selector:
    matchLabels:
      app: eureka
  template:
    metadata:
      labels:
        app: eureka
    spec:
      containers:
      - name: eureka
        image: bitinit/eureka
        ports:
        - containerPort: 8761
        resources:
          requests:
            memory: "1Gi"
            cpu: "500m"
          limits:
            memory: "1200Mi"
            cpu: "500m"
        env:
        - name: EUREKA_SERVER_ADDRESS
          valueFrom:
            configMapKeyRef:
              name: eureka-cm
              key: eureka_service_address
        - name: ENVIRONMENT
          value: "prod"
        - name: JVM_OPTS
          value: "-Xms1g -Xmx1g"
        livenessProbe:
          httpGet:
            path: /
            port: 8761
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            path: /
            port: 8761
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 5

# 2.执行yml文件创建pod

代码语言:javascript复制
[root@master ~]# kubectl apply -f k8s-eureka-prod.yml 
configmap/eureka-cm created
service/eureka-np created
service/eureka created
statefulset.apps/eureka created
[root@master ~]# kubectl get pods
NAME       READY   STATUS              RESTARTS   AGE
eureka-0   0/1     ContainerCreating   0          6s
[root@master ~]# kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
eureka-0   1/1     Running   3          6m36s
eureka-1   0/1     Running   1          2m8s
[root@master ~]# kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
eureka-0   1/1     Running   3          6m40s
eureka-1   0/1     Running   1          2m12s
[root@master ~]# kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
eureka-0   1/1     Running   3          6m41s
eureka-1   0/1     Running   1          2m13s
[root@master ~]# kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
eureka-0   1/1     Running   3          6m41s
eureka-1   0/1     Running   1          2m13s
[root@master ~]# kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
eureka-0   1/1     Running   3          6m42s
eureka-1   0/1     Running   1          2m14s
[root@master ~]# kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
eureka-0   1/1     Running   3          6m43s
eureka-1   0/1     Running   1          2m15s
[root@master ~]# kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
eureka-0   1/1     Running   3          6m43s
eureka-1   0/1     Running   1          2m15s
[root@master ~]# kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
eureka-0   1/1     Running   3          15m
eureka-1   1/1     Running   1          11m
eureka-2   1/1     Running   2          8m54s

# 结果展示

浏览器访问各个节点的IP:28600 都可以查看注册中心哟

0 人点赞