学习k8s
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
mkdir ~/.kube
|
||||
# mkdir ~/.kube
|
||||
|
||||
cp ./config ~/.kube/config
|
||||
@@ -4,7 +4,7 @@ K109668b353a17ff6ea9d68535255f880cf583c5c83c357d181ac5f963505033af4::server:f95b
|
||||
|
||||
```sh
|
||||
|
||||
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://kevisual.cn:6443 K3S_TOKEN=K109668b353a17ff6ea9d68535255f880cf583c5c83c357d181ac5f963505033af4::server:f95b219abcfe507760f04ff88be52ccd sh -
|
||||
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://kevisual.cn:6443 K3S_TOKEN=K109668b353a17ff6ea9d68535255f880cf583c5c83c357d181ac5f963505033af4::server:f95b219abcfe507760f04ff88be52ccd sh - --pause-image=docker.m.daocloud.io/rancher/mirrored-pause:3.9
|
||||
|
||||
```
|
||||
会输出类似
|
||||
|
||||
11
k8s/readme.md
Normal file
11
k8s/readme.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# 设置默认 context
|
||||
```sh
|
||||
kubectl config use-context <context-name>
|
||||
|
||||
|
||||
kubectl config use-context dev-context
|
||||
```
|
||||
|
||||
# 查看节点信息
|
||||
```sh
|
||||
kubectl get nodes -o wide
|
||||
3
k8s/xiongxiao.me/config/env.md
Normal file
3
k8s/xiongxiao.me/config/env.md
Normal file
@@ -0,0 +1,3 @@
|
||||
```sh
|
||||
cat /etc/systemd/system/k3s.service.env
|
||||
```
|
||||
@@ -24,4 +24,32 @@ kubectl label nodes vm-32-6-ubuntu machine- --overwrite
|
||||
kubectl label nodes on machine=on --overwrite
|
||||
### light
|
||||
|
||||
kubectl label nodes light machine=light --overwrite
|
||||
kubectl label nodes light machine=light --overwrite
|
||||
|
||||
|
||||
## 关于非内网需要设置实际ip地址
|
||||
|
||||
```sh
|
||||
# aliyun, ip: 121.199.37.154
|
||||
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_NODE_IP=121.199.37.154 K3S_NODE_EXTERNAL_IP=121.199.37.154 K3S_URL=https://light.xiongxiao.me:6443 K3S_TOKEN=K1035ea36d4925cfd0a7f7938fb3eff1225e458c1aee4fb99bda40bb95f529913bf::server:03e3ef7d17dadc2471b0f2369248250d sh -
|
||||
--pause-image=docker.m.daocloud.io/rancher/mirrored-pause:3.9
|
||||
|
||||
|
||||
kubectl label nodes aliyun machine=aliyun --overwrite
|
||||
|
||||
```
|
||||
|
||||
手动创建配置文件
|
||||
```sh
|
||||
# 停止 k3s-agent 服务
|
||||
sudo systemctl stop k3s-agent
|
||||
|
||||
# 编辑配置文件
|
||||
sudo vim /etc/systemd/system/k3s-agent.service.env
|
||||
|
||||
# 重新加载 systemd 配置
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
# 启动服务
|
||||
sudo systemctl start k3s-agent
|
||||
```
|
||||
@@ -63,11 +63,11 @@ sudo systemctl restart containerd
|
||||
sudo ctr image pull docker.io/library/verdaccio:latest
|
||||
|
||||
# K3s 使用 k8s.io 命名空间
|
||||
sudo ctr -n k8s.io images pull docker.m.daocloud.io/rancher/mirrored-pause:3.6
|
||||
sudo ctr -n k8s.io images pull docker.m.daocloud.io/rancher/mirrored-pause:3.9
|
||||
|
||||
sudo ctr -n k8s.io images tag docker.m.daocloud.io/rancher/mirrored-pause:3.6 docker.io/rancher/mirrored-pause:3.6
|
||||
sudo ctr -n k8s.io images tag docker.m.daocloud.io/rancher/mirrored-pause:3.9 docker.io/rancher/mirrored-pause:3.9
|
||||
|
||||
sudo ctr -n k8s.io images delete docker.m.daocloud.io/rancher/mirrored-pause:3.6
|
||||
sudo ctr -n k8s.io images delete docker.m.daocloud.io/rancher/mirrored-pause:3.9
|
||||
|
||||
|
||||
# 查看镜像
|
||||
|
||||
@@ -10,7 +10,9 @@ sudo cat /var/lib/rancher/k3s/server/node-token
|
||||
|
||||
## 2. 安装 node
|
||||
```sh
|
||||
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -
|
||||
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh |
|
||||
INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh - - \
|
||||
--system-default-registry=registry.cn-hangzhou.aliyuncs.com
|
||||
```
|
||||
|
||||
## 3. 删除
|
||||
|
||||
62
k8s/xiongxiao.me/test/hello/hello.yaml
Normal file
62
k8s/xiongxiao.me/test/hello/hello.yaml
Normal file
@@ -0,0 +1,62 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: hello-world
|
||||
labels:
|
||||
app: hello-world
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: hello-world
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: hello-world
|
||||
spec:
|
||||
nodeSelector:
|
||||
machine: aliyun
|
||||
containers:
|
||||
- name: hello
|
||||
image: docker.cnb.cool/kevisual/hello
|
||||
ports:
|
||||
- containerPort: 80
|
||||
protocol: TCP
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: hello-world
|
||||
labels:
|
||||
app: hello-world
|
||||
spec:
|
||||
selector:
|
||||
app: hello-world
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 80
|
||||
nodePort: 30081
|
||||
type: NodePort
|
||||
|
||||
# http://121.199.37.154:30081/
|
||||
|
||||
# 1.查看 Deployment 状态:
|
||||
# kubectl get deployment hello-world
|
||||
# kubectl logs deployment/hello-world
|
||||
# 2. 查看 Pod 状态:
|
||||
# kubectl get pods -l app=hello-world
|
||||
|
||||
# 3.查看 Pod 详细信息(包括事件):
|
||||
# kubectl describe pod -l app=hello-world
|
||||
|
||||
# 4. delete all
|
||||
# kubectl delete -f hello.yaml
|
||||
|
||||
# 5. delete pod
|
||||
# kubectl delete pod -l app=hello-world
|
||||
|
||||
# 6. rollupdate
|
||||
# kubectl set image deployment/hello-world hello=docker.cnb.cool/kevisual/hello:latest
|
||||
|
||||
# 7. 进入 Pod
|
||||
# kubectl exec -it deployment/hello-world -- /bin/sh
|
||||
Reference in New Issue
Block a user