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 : 1 selector : 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/null resources : 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 : 8888 targetPort : 8888 type : NodePort