在WSL2中安装Arch Linux

公司办公PC是Windows,日常又会使用到一些linux做一些实验性工作,今天无意间看到了在WSL安装Archlinux。记录了一下安装过程。

阅读更多

Manjaro安装vscode和edge

这个方法是从archlinux build源手工安装软件。首先需要安装基础的软件包,再下载源编译和安装。

阅读更多

使用pandoc生成PPT常用命令

使用markdown + marp或者markdown + revealjs可以写PPT。使文档写作过程只专注于写作本身而不是各种格式。其实第一次还是要将常用的格式做好调试(主要是写一些常用的css文件自定义样式),后续则可以在markdown->html/PDF/docx/pptx/ebook间随意转换了。

以下主要记录几个常用命令,完整的pandoc手册可以参考:https://pandoc.org/MANUAL.html

  • markdown 2 pptx pandoc mark.md -o mark.pptx --reference-doc=template.potx

  • mardown 2 revealjs pandoc -t revealjs mark.md -o mark.html --self-contained -V revealjs-url=./reveal.js/ --css=custom.css

-t 参数还可以设置成s5, slidy, slideous, dzslides; -V revealjs-url 可以制定本地目录reveal.js, 将https://github.com/hakimel/reveal.js下载本地即可; -css 可以制定css附件,通过定制css文件可以调整显示样式。

  • 对于revealjs可以在文件中设置width和height调整显示大小
    • markdown文件示例文件如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    ---
    title: 使用pandoc生成PPT常用命令
    theme: white
    width: 1920
    height: 1280
    author:
    - author
    date: 2021-09-14
    ---

    # markdown2pptx

    `pandoc mark.md -o mark.pptx --reference-doc=template.potx`

    ---

    # markdown2revealjs

    `pandoc -t revealjs mark.md -o mark.html --self-contained -V revealjs-url=./reveal.js/ --css=custom.css`

    • css文件示例
    1
    2
    3
    .reveal h1{
    color:olivedrab
    }

配置Manjaro Linux上ibus-rime输入法

在Manjaro系统中不能直接通过ibus-setup设置ibus-rime显示模式为水平模式(可能是Manjaro的bug)只能设置字体和文字大小。可以通过直接修改ibus-rime配置文件配置想要的显示方式。

ibus-rime的配置文件默认在~/.config/ibus/rime/build/目录下,直接将horizontal配置项修改成true即可。

其他的ibus配置可以参考https://wiki.archlinux.org/title/IBus

minikube addons enable ingress

由于大家都知道到原因,国内无法直接访问gcr.io和quay.io很多Kubernetes相关镜像无法从国内下载,网上很多大神也给出了薅aliyun羊毛的方案,我自己也试了几次也总是不能成功,使用aliyun提供minikube的版本也总是无法启动ingress。

通过查看启动ingress失败的POD信息发现是无法下载使用到镜像,于是按照网络指导按照如下步骤提前下载镜像到minikube节点,再启动ingress即可成功,具体操作如下:

  • 查询minikube版本对应的ingress镜像版本 使用kubectl get po -A查询ingress对应POD

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    kubectl get po -A
    NAMESPACE NAME READY STATUS RESTARTS AGE
    kube-system coredns-546565776c-xgggd 1/1 Running 0 27m
    kube-system etcd-minikube 1/1 Running 0 27m
    kube-system ingress-nginx-admission-create-d9dtl 0/1 Completed 0 28s
    kube-system ingress-nginx-admission-patch-x67q7 0/1 Completed 1 28s
    kube-system ingress-nginx-controller-7bb4c67d67-hp5c7 0/1 ContainerCreating 0 28s
    kube-system kube-apiserver-minikube 1/1 Running 0 27m
    kube-system kube-controller-manager-minikube 1/1 Running 0 27m
    kube-system kube-proxy-7wbct 1/1 Running 0 27m
    kube-system kube-scheduler-minikube 1/1 Running 0 27m
    kube-system storage-provisioner 1/1 Running 0 27m

    其中名字中包含ingress就是启动ingress新建到POD。

    再使用kubectl describe po ingress-nginx-xxx --namespace kube-system查询具体的失败信息,即可查询到失败原因为:获取镜像失败/超时。由于minikube 1.12.0版本以上的ingress镜像目前在阿里云上也无法下载,我们将minikube的版本切换到1.12.0版本,此时查询到的ingress插件依赖镜像信息如下:

    1
    2
    quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.32.0
    jettech/kube-webhook-certgen:v1.2.0

  • 手动安装ingress镜像 使用minikube ssh登录到minikube的节点上,再动过docker命令手工pull镜像。

    1
    2
    3
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:0.32.0
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:0.32.0 quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.32.0
    docker pull jettech/kube-webhook-certgen:v1.2.0

    quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.32.0 镜像可以由aliyun的镜像替代,再重新Tag成原有镜像。

  • 再次启用ingress 上述操作均成功以后可以再次启动ingress插件即可秒成功 :)

Kubernetes部署和升级应用

之前文章中我们都是用POD部署应用,特别是用POD部署应用时如果要更新应用程序,必须先更新镜像(Image)/配置(ConfigMap),删除POD再重新部署应用程序才能整整的更新。Kubernetes提供了更高级的应用部署和升级方法。

使用ReplicationController部署应用

   如果用ReplicationController(RC)部署的应用可以通过RC update来更新应用。 具体的kubia-rc.yaml文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
kind: ReplicationController
metadata:
name: kubia
spec:
replicas: 3
selector:
app: kubia
template:
metadata:
name: kubia
labels:
app: kubia
spec:
containers:
- name: kubia
image: 172.17.0.1:5000/kubia:v1
ports:
- containerPort: 3000

使用kubectl create -f kubia-rc.yaml创建RC,部署成功以后即可看到根据RC的配置会产生3个副本kubectl get rc,po

1
2
3
4
5
6
7
8
9
kubectl get po,rc
NAME READY STATUS RESTARTS AGE
pod/kubia-bqszw 1/1 Running 0 62s
pod/kubia-c4cb9 1/1 Running 0 62s
pod/kubia-wxj55 1/1 Running 0 62s

NAME DESIRED CURRENT READY AGE
replicationcontroller/kubia 3 3 3 62s

当前POD到到镜像版本为v1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
kubectl describe po
Name: kubia-bqszw
Namespace: default
Priority: 0
Node: minikube/172.17.0.3
Start Time: Wed, 14 Oct 2020 20:29:56 +0800
Labels: app=kubia
Annotations: <none>
Status: Running
IP: 172.18.0.3
IPs:
IP: 172.18.0.3
Controlled By: ReplicationController/kubia
Containers:
kubia:
Container ID: docker://ec65afaeea2e8726530863981512165bec02ceb8e953a3d6575f6ea4ad7cc3f3
Image: 172.17.0.1:5000/kubia:v1
Image ID: docker-pullable://172.17.0.1:5000/kubia@sha256:0a9705988c08da5cc4fd535f40216a7b0ef89325b594ddb97ffcbd220c6731f1
...

通过kubectl set image rc/kubia kubia=172.17.0.1:5000/kubia:v2更新镜像。此时的应用程序并不会自动更新。当POD 异常或者手工删除以后RC 会自动拉起一个POD ,保证POD的副本数和RC 中配置的一致,此时新的POD 就是使用新的镜像创建应用,也就是说有的POD 使用新的镜像,有的POD 使用老的镜像。可以通过kubectl describe po查询到POD中容器的镜像版本不同。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
kubectl describe po
Name: kubia-c4cb9
Namespace: default
Priority: 0
Node: minikube/172.17.0.3
Start Time: Wed, 14 Oct 2020 20:29:56 +0800
Labels: app=kubia
Annotations: <none>
Status: Running
IP: 172.18.0.4
IPs:
IP: 172.18.0.4
Controlled By: ReplicationController/kubia
Containers:
kubia:
Container ID: docker://2b259af30a0c75987f027ac4516a7ea368774bbac4259a732f8141fdbcae376a
Image: 172.17.0.1:5000/kubia:v1
Image ID: docker-pullable://172.17.0.1:5000/kubia@sha256:0a9705988c08da5cc4fd535f40216a7b0ef89325b594ddb97ffcbd220c6731f1
Port: 3000/TCP
Host Port: 0/TCP
State: Running
Started: Wed, 14 Oct 2020 20:30:04 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-d2hsm (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-d2hsm:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-d2hsm
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 6m43s default-scheduler Successfully assigned default/kubia-c4cb9 to minikube
Normal Pulled 6m36s kubelet Container image "172.17.0.1:5000/kubia:v1" already present on machine
Normal Created 6m36s kubelet Created container kubia
Normal Started 6m35s kubelet Started container kubia


Name: kubia-s6822 ‹--自动使用新的镜像创建新的POD
Namespace: default
Priority: 0
Node: minikube/172.17.0.3
Start Time: Wed, 14 Oct 2020 20:35:57 +0800
Labels: app=kubia
Annotations: <none>
Status: Running
IP: 172.18.0.6
IPs:
IP: 172.18.0.6
Controlled By: ReplicationController/kubia
Containers:
kubia:
Container ID: docker://91fd664961c798256afbfd9b2e6cd47697a817f27803812da26e28d56212371e
Image: 172.17.0.1:5000/kubia:v2
Image ID: docker-pullable://172.17.0.1:5000/kubia@sha256:0709bbd6e3a34f306a16207b79b045e6a4bf33c22a3e7a88404166caee41e51f
Port: 3000/TCP
Host Port: 0/TCP
State: Running
Started: Wed, 14 Oct 2020 20:36:02 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-d2hsm (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-d2hsm:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-d2hsm
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 42s default-scheduler Successfully assigned default/kubia-s6822 to minikube
Normal Pulled 38s kubelet Container image "172.17.0.1:5000/kubia:v2" already present on machine
Normal Created 37s kubelet Created container kubia
Normal Started 37s kubelet Started container kubia


Name: kubia-wxj55
Namespace: default
Priority: 0
Node: minikube/172.17.0.3
Start Time: Wed, 14 Oct 2020 20:29:56 +0800
Labels: app=kubia
Annotations: <none>
Status: Running
IP: 172.18.0.2
IPs:
IP: 172.18.0.2
Controlled By: ReplicationController/kubia
Containers:
kubia:
Container ID: docker://a5195a7ec8573d429445f7c79218372abc887d360b3564c8659b600c236c0248
Image: 172.17.0.1:5000/kubia:v1
Image ID: docker-pullable://172.17.0.1:5000/kubia@sha256:0a9705988c08da5cc4fd535f40216a7b0ef89325b594ddb97ffcbd220c6731f1
Port: 3000/TCP
Host Port: 0/TCP
State: Running
Started: Wed, 14 Oct 2020 20:30:04 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-d2hsm (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-d2hsm:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-d2hsm
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 6m44s default-scheduler Successfully assigned default/kubia-wxj55 to minikube
Normal Pulled 6m36s kubelet Container image "172.17.0.1:5000/kubia:v1" already present on machine
Normal Created 6m36s kubelet Created container kubia
Normal Started 6m35s kubelet Started container kubia

使用ReplicationController部署应用,需要手工选择POD 逐一进行升级。实际部署应用过程中我们希望这个过程可以可控、且自动完成,这就需要通过更高级更高级的概念来部署应用。

使用Deployment部署应用

   Kubernetes提供更高级的概念来实现应用的部署、滚动升级以及回滚。一个典型的kubernetes的应用会包含:POD、RepliciaSet以及Deployment。他们之间的关系如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubia
spec:
replicas: 3
selector:
matchLabels:
app: kubia
template:
metadata:
labels:
app: kubia
spec:
containers:
- name: kubia
image: 172.17.0.1:5000/kubia:v1

还是上面的例子,这次将ReplicationController的yaml文件中kinde替换城Deployment,并另存为kubia-deploymnent.yaml,使用kubectl create -f kubia-deployment.yaml重新部署应用,部署成功以后可以功过kubectl get po,rs,deployment查询部署的应用情况。

1
2
3
4
5
6
7
8
9
10
11
12
kubectl get po,rs,deployment
NAME READY STATUS RESTARTS AGE
pod/kubia-7fc889c9c9-b7b8f 1/1 Running 1 21h
pod/kubia-7fc889c9c9-lp7m8 1/1 Running 1 21h
pod/kubia-7fc889c9c9-qkz9w 1/1 Running 1 21h

NAME DESIRED CURRENT READY AGE
replicaset.apps/kubia-7fc889c9c9 3 3 3 21h

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/kubia 3/3 3 3 21h

通过kubectl descibe po查询到POD到详细情况如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
kubectl describe po
Name: kubia-7fc889c9c9-b7b8f
Namespace: default
Priority: 0
Node: minikube/172.17.0.3
Start Time: Tue, 13 Oct 2020 22:44:19 +0800
Labels: app=kubia
pod-template-hash=7fc889c9c9
Annotations: <none>
Status: Running
IP: 172.18.0.2
IPs:
IP: 172.18.0.2
Controlled By: ReplicaSet/kubia-7fc889c9c9
Containers:
kubia:
Container ID: docker://aa524c986c27e53d12961173a5a0adf43a3554e13aeac5fc1c5cca083da09271
Image: 172.17.0.1:5000/kubia:v1 ‹-- 镜像版本是v1
Image ID: docker-pullable://172.17.0.1:5000/kubia@sha256:0a9705988c08da5cc4fd535f40216a7b0ef89325b594ddb97ffcbd220c6731f1
...

更新应用

  • 配置更新镜像

kubectl set image deployment/kubia kubia=172.17.0.1:5000/kubia:v2

设置完成以后deployment会自动滚动升级,可以通过kubectl rollout deployment/kubia status查询升级状态,此时查询应用部署的详情可以看到PO,RS更新中或者已经更新成功。 kubectl get po,rs,deployment 其中存在2个rs,一个升级前的rs,一个是当前到rs。

1
2
3
4
5
6
7
8
9
10
11
12
13
kubectl get po,rs,deployment
NAME READY STATUS RESTARTS AGE
pod/kubia-7fc889c9c9-b7b8f 1/1 Running 1 21h
pod/kubia-7fc889c9c9-lp7m8 1/1 Running 1 21h
pod/kubia-7fc889c9c9-qkz9w 1/1 Running 1 21h
pod/kubia-84ddcd9474-bv8fl 0/1 ContainerCreating 0 3s ‹-- 新建POD

NAME DESIRED CURRENT READY AGE
replicaset.apps/kubia-7fc889c9c9 3 3 3 21h ‹-- 升级前的rs
replicaset.apps/kubia-84ddcd9474 1 1 0 4s ‹-- 当前的rs

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/kubia 3/3 1 3 21h

查询POD详细信息,可以看到新建到POD已经更新为新到镜像。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
kubectl describe po kubia-84ddcd9474-bv8fl                                  ‹-- 新建POD
Name: kubia-84ddcd9474-bv8fl
Namespace: default
Priority: 0
Node: minikube/172.17.0.3
Start Time: Wed, 14 Oct 2020 20:19:12 +0800
Labels: app=kubia
pod-template-hash=84ddcd9474
Annotations: <none>
Status: Running
IP: 172.18.0.6
IPs:
IP: 172.18.0.6
Controlled By: ReplicaSet/kubia-84ddcd9474
Containers:
kubia:
Container ID: docker://3de190659e28bebcde082b287c7c4c434ab706c08654f6d1c7db3db455304508
Image: 172.17.0.1:5000/kubia:v2 ‹-- 镜像版本是v2
Image ID: docker-pullable://172.17.0.1:5000/kubia@sha256:0709bbd6e3a34f306a16207b79b045e6a4bf33c22a3e7a88404166caee41e51f

  • 管理升级

此时如果使用kubectl rollout undo deployment/kubia 即可全部回滚应用,可以通过kubectl rollout pause/resume/restart/history等控制滚动升级过程(如果测试过程中难以观察到升级过程,可以讲deployment中副本数量调高)。


此外,也可以使用StatefulSet部署有状态应用。StatefulSet和Deployment最大的区别是为每个副本POD实例提供店里存储,可以保证POD副本有固定的名字和主机,可以按照预期的顺序启停POD副本。