k8s常用创建的命名空间、pod、service

k8s常用创建的命名空间、pod、service

使用 Namespaces

Namespace的创建、删除和查看。

创建

(1) 命令行直接创建
$ kubectl create namespace new-namespace

(2) 通过文件创建
$ cat my-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: new-namespace

$ kubectl create -f ./my-namespace.yaml

注意:命名空间名称满足正则表达式[a-z0-9]([-a-z0-9]*[a-z0-9])?,最大长度为63位

删除

$ kubectl delete namespaces new-namespace

PV

hostPath

hostPath允许挂载Node上的文件系统到Pod里面去。如果Pod需要使用Node上的文件,可以使用hostPath。

示例

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: gcr.io/google_containers/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      # directory location on host
      path: /data

实例:

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: zookeeper-devdata-1
  namespace: injured-dev
spec:
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteOnce
  nfs:
    server: 172.16.207.1
    path: /data/zookeeperdev/zookeeper-datadir-1

猜你喜欢

转载自blog.csdn.net/guoshaoliang789/article/details/86528718