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
spec:
replicas: 1
selector:
matchLabels:
app: jupyter
template:
metadata:
labels:
app: jupyter
spec:
containers:
- name: jupyter
image: pyflink:20250109
securityContext:
privileged: true
ports:
- containerPort: 8888
volumeMounts:
- name: work-volume
mountPath: /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
新增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