kubernetes学习

k8s部署registry服务

2019-12-16  本文已影响0人  sjyu_eadd

deployment定义如下registry_deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: registry
  namespace: default
  labels:
    app: registry
    kubernetes.io/cluster-service: "true"
spec:
  replicas: 2
  selector:
    matchLabels:
      app: registry
  template:
    metadata:
      labels:
        app: registry
        kubernetes.io/cluster-service: "true"
    spec:
      containers:
      - name: registry
        image: registry:2
        resources:
          limits:
            cpu: 100m
            memory: 100Mi
        env:
        - name: REGISTRY_HTTP_ADDR
          value: :5000
        - name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY
          value: /var/lib/registry
        volumeMounts:
        - name: image-store
          mountPath: /var/lib/registry
        ports:
        - containerPort: 5000
          name: registry
          protocol: TCP
      volumes:
      - name: image-store
        nfs:
        # Use real NFS server address here.
          server: 192.168.125.5
        # Use real NFS server export directory.
          path: "/nfs"

执行kubectl apply -f registry_deployment.yaml

service定义如下registry_service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: registry
  namespace: default
  labels:
    app: registry
    kubernetes.io/cluster-service: "true"
spec:
  selector:
    app: registry
  ports:
  - name: registry
    port: 5000
    protocol: TCP

执行kubectl apply -f registry_service.yaml

[root@hanyu-210 ~]# kubectl get pods -o wide|grep registry
registry-f5f596ccd-8xqd6                       1/1     Running   0          18m     10.244.2.26   hanyu-212   <none>           <none>
registry-f5f596ccd-dphc9                       1/1     Running   0          6m52s   10.244.0.7    hanyu-210   <none>           <none>
[root@hanyu-210 ~]# kubectl describe services registry
Name:              registry
Namespace:         default
Labels:            app=registry
                   kubernetes.io/cluster-service=true
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"registry","kubernetes.io/cluster-service":"true"},"name"...
Selector:          app=registry
Type:              ClusterIP
IP:                10.104.212.191
Port:              registry  5000/TCP
TargetPort:        5000/TCP
Endpoints:         10.244.0.7:5000,10.244.2.26:5000
Session Affinity:  None
Events:            <none>
[root@hanyu-210 ~]# kubectl get endpoints registry -o yaml
apiVersion: v1
kind: Endpoints
metadata:
  annotations:
    endpoints.kubernetes.io/last-change-trigger-time: "2019-12-16T11:48:51Z"
  creationTimestamp: "2019-12-16T11:42:10Z"
  labels:
    app: registry
    kubernetes.io/cluster-service: "true"
  name: registry
  namespace: default
  resourceVersion: "2683329"
  selfLink: /api/v1/namespaces/default/endpoints/registry
  uid: d64dfbfe-7112-44d0-97c8-173ca0920b57
subsets:
- addresses:
  - ip: 10.244.0.7
    nodeName: hanyu-210
    targetRef:
      kind: Pod
      name: registry-f5f596ccd-dphc9
      namespace: default
      resourceVersion: "2683328"
      uid: 6037058c-2816-4e8c-8f31-cf6babbf1226
  - ip: 10.244.2.26
    nodeName: hanyu-212
    targetRef:
      kind: Pod
      name: registry-f5f596ccd-8xqd6
      namespace: default
      resourceVersion: "2682235"
      uid: 7932e654-07db-4c00-89b2-e56a1911c27d
  ports:
  - name: registry
    port: 5000
    protocol: TCP
上一篇 下一篇

猜你喜欢

热点阅读