介绍
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| cat <<EOF >mongo.yml --- apiVersion: v1 kind: Service metadata: namespace: default name: mongo labels: app: mongo spec: ports: - port: 27017 protocol: TCP selector: app: mongo --- apiVersion: apps/v1beta1 kind: StatefulSet metadata: namespace: default name: mongo labels: app: mongo spec: serviceName: "mongo" replicas: 1 template: metadata: labels: app: mongo spec: containers: - name: mongo image: mongo ports: - containerPort: 27017 volumeMounts: - name: mongo-persistent-storage mountPath: /data/db volumes: - name: "mongo-persistent-storage" emptyDir: {}
EOF
|
1 2 3 4 5 6 7 8 9 10 11
| kubectl apply -f mongo.yml
kubectl get all -l app=mongo NAME READY STATUS RESTARTS AGE pod/mongo-0 1/1 Running 0 45s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/mongo ClusterIP 10.101.126.132 <none> 27017/TCP 46s
NAME READY AGE statefulset.apps/mongo 1/1 45s
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| cat <<EOF >spring-boot-simple.yml --- apiVersion: v1 kind: Service metadata: namespace: default name: spring-boot-simple labels: app: spring-boot-simple spec: type: NodePort ports: - port: 8080 protocol: TCP selector: app: spring-boot-simple --- apiVersion: apps/v1 kind: Deployment metadata: namespace: default name: spring-boot-simple labels: app: spring-boot-simple spec: replicas: 1 selector: matchLabels: app: spring-boot-simple template: metadata: labels: app: spring-boot-simple spec: containers: - image: gjeanmart/spring-boot-simple:0.0.1-SNAPSHOT imagePullPolicy: Always name: spring-boot-simple env: - name: SPRING_DATA_MONGODB_HOST value: mongo ports: - containerPort: 8080 EOF
|
1
| kubectl apply -f spring-boot-simple.yml
|
1 2 3 4 5 6 7 8 9 10 11 12
| kubectl get all -l app=spring-boot-simple NAME READY STATUS RESTARTS AGE pod/spring-boot-simple-767bb94595-q8fls 1/1 Running 0 22s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/spring-boot-simple NodePort 10.96.25.63 <none> 8080:30401/TCP 23s
NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/spring-boot-simple 1/1 1 1 22s
NAME DESIRED CURRENT READY AGE replicaset.apps/spring-boot-simple-767bb94595 1 1 1 22s
|
1 2
| curl -X GET http: Greetings from Spring Boot!
|
Post a message
1 2
| curl -X POST http://192.168.10.25:30401/message -d 'hello world' {"id":"5dba968cc2892e0001eb0673","message":"hello+world=","postedAt":"2019-10-31T08:08:44.860+0000"}
|
Get all messages
1 2
| curl -X GET http: [{"id":"5dba968cc2892e0001eb0673","message":"hello+world=","postedAt":"2019-10-31T08:08:44.860+0000"}]
|
1
| kubectl create namespace monitoring
|
或apply
1 2 3 4 5 6 7
| cat <<EOF >monitoring-namespace.yml --- apiVersion: v1 kind: Namespace metadata: name: monitoring EOF
|
https://kauri.io/article/b3be4dbf895b433f93b3cb589d414988