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-pvcnamespace: jupyter
spec:accessModes:- ReadWriteOnceresources:requests:storage: 10Gi
新增deployment
apiVersion: apps/v1
kind: Deployment
metadata:name: jupyternamespace: jupyter
spec:replicas: 1selector:matchLabels:app: jupytertemplate:metadata:labels:app: jupyterspec:containers:- name: jupyterimage: pyflink:20250109 securityContext:privileged: true ports:- containerPort: 8888 volumeMounts:- name: work-volumemountPath: /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/nullresources:requests:cpu: "2000m"memory: "4Gi"limits:cpu: "4000m"memory: "8Gi"volumes:- name: work-volumepersistentVolumeClaim:claimName: jupyter-work-pvc
新增service
apiVersion: v1
kind: Service
metadata:name: jupyternamespace: jupyter
spec:selector:app: jupyterports:- name: jupyter-portprotocol: TCPport: 8888targetPort: 8888type: NodePort