k8s新增jupyter服务

发布于:2025-07-12 ⋅ 阅读:(18) ⋅ 点赞:(0)

k8s新增服务

常用命令

  • kubectl apply -f xxxxxx.yaml # 部署资源,顺序:namespace -> pvc -> deployment -> service
  • kubectl create namespace jupyter # 创建namespace
  • kubectl get namespaces # 查看ns
  • kubectl get pods -n jupyter # 查看pods
  • kubectl logs jupyterlab -n jupyter # 查看pod日志
  • kubectl get svc jupyter -n jupyter # 查看 svc 和 nodeport
  • kubectl get deployment -n jupyter # 查看 deployment
  • kubectl get pods -A # 查看所有ns下的pod
  • kubectl get all -n jupyter # 查看ns下的所有资源
  • kubectl describe [deployment|svc] jupyter -n jupyter # 详细信息,可以查看事件
  • kubectl edit deployment jupyter -n jupyter # 命令行编辑yaml,保存后立即生效
  • kubectl apply -f jupyter-deployment.yaml # 应用更新后的yaml

新增namespace

apiVersion: v1
kind: Namespace
metadata:
  name: jupyter
新增pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jupyter-work-pvc
  namespace: jupyter
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

新增deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jupyter
  namespace: jupyter  # 假设你已经创建了 jupyter 这个 Namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jupyter
  template:
    metadata:
      labels:
        app: jupyter
    spec:
      containers:
      - name: jupyter
        image: pyflink:20250109  # 安装了python notebook 的镜像
        securityContext:
          privileged: true  # 对应 docker-compose 的 privileged: true
        ports:
        - containerPort: 8888  # Jupyter Notebook 端口
        volumeMounts:
        - name: work-volume
          mountPath: /work     # 挂载 /work 目录
        command: ["/bin/sh", "-c"]
        args:
          - |
            cd /
            nohup jupyter notebook --ip 0.0.0.0 --port 8888 --allow-root --NotebookApp.password=sha1:6587feaef3b1:6b243404e4cfaafe611fdf494ee71fdaa8c4a563 2>&1 > /work/.jupyter.log &
            # 保持主进程运行
            tail -f /dev/null
        resources:
          requests:
            cpu: "2000m"
            memory: "4Gi"
          limits:
            cpu: "4000m"
            memory: "8Gi"
      volumes:
      - name: work-volume
        persistentVolumeClaim:
          claimName: jupyter-work-pvc  # 挂载 PVC(持久化 /work 目录)

新增service

apiVersion: v1
kind: Service
metadata:
  name: jupyter
  namespace: jupyter
spec:
  selector:
    app: jupyter
  ports:
  - name: jupyter-port
    protocol: TCP
    port: 8888
    targetPort: 8888
  type: NodePort  # 使用 NodePort 类型暴露服务

网站公告

今日签到

点亮在社区的每一天
去签到