K8S(2)

发布时间 2023-04-13 11:11:37作者: ZZX11
title: FIT 5225ASS1

instance位置

https://cloud.oracle.com/compute/instances?region=ap-melbourne-1

接入指令 master

ssh -i ssh-key-1.key ubuntu@YOUR_IP

接入指令 worker

ssh -i ssh-key-2.key ubuntu@YOUR_IP

文件上传指令

scp -i ssh-key-1.key -r 路径 ubuntu@YOUR_IP:

文件删除指令

rm -rf /path/to/folder/*

前端执行指令

python3 iWebLens_client.py inputfolder http://localhost:5000/api/weblens 4

先尝试部署网站的后端

1.首先注册dockerhub账号,上传images到Dockerhub

创建镜像

docker build -t iweblens-server:latest .

上传到dockerhub 参考下面的做法

https://www.bilibili.com/video/BV11L411g7U1/?p=7&vd_source=5e78312fb5f90b9c83a318189a70a5c0

docker push 自己的镜像

2.在master上

按照tutorial5创建虚拟机+关键配置,注意要在ingress放开自己要用的端口限制

文件上传指令将自己client和K8S-config上传

kubectl apply -f K8S-config.yaml

kubectl get nodes,deployments,pods --namespace=default -o wide 查看pod

kubectl get svc 查看service

kubectl describe service serviceID 查看细节

3.用到的指令总结

kubectl get pod -n kube-system 查看系统中的pod
kubectl get pod
kubectl get node
kubectl get pod -n default -o wide|grep weblens 看pod ip地址
kubectl get nodes,deployments,pods --namespace=default -o wide
kubectl get svc
kubectl get pod -o wide该命令将显示 Pod 的名称、状态、IP 地址、所属的命名空间、容器名称等基本信息
kubectl get pod -n kube-system 查看系统中的pod

kubectl describe service weblens-entry看详细配置

kubectl apply -f service.yaml  部署service

kubectl replace -f k8s-config.yaml 更新pod

sudo journalctl -u kubelet -n 100 --no-pager  查看node节点日志
kubectl describe pod weblens-84dd4f956b-6tbfn --namespace=kube-system

kubectl  describe node k8s-worker1| grep Taints 查看污点 
去除污点:
kubectl taint nodes k8s-worker1 node.kubernetes.io/not-ready:NoSchedule-
kubectl taint nodes k8s-master node-role.kubernetes.io/control-plane:NoSchedule-

进入docker容器 :
docker exec -ti your-container-name /bin/sh
进入pod:
kubectl exec -it test-pod -n test -- /bin/sh

netstat -antp |grep :30001 查看端口
iptables -L -n 查看iptable
sudo iptables -S -t nat 
此命令将列出所有当前生效的 NAT 规则,并以可读性较好的格式显示它们的详细信息,例如源 IP 地址、目标 IP 地址、协议类型、端口号等等。

kubectl port-forward service/weblens-entry 80:30000
要将 Kubernetes 集群中的 weblens-entry Service 的 NodePort 端口映射到本地机器的 80 端口上