k3sとは
- プチKubernetes
- 超軽い 40MBくらい
- k8sから5機能が削がれている
- mac,windowsでは使用できず、Linuxだけ
環境
- AWS EC2
- Amazon Linux 2
k3sのインストール
1 2 3 4 |
yum -y install wget cd /usr/local/bin/ wget https://github.com/rancher/k3s/releases/download/v0.2.0/k3s chmod 755 ./k3s |
起動
1 |
k3s server & |
起動確認
1 2 3 4 5 |
# k3s kubectl get node NAME STATUS ROLES AGE VERSION ip-172-31-37-113.ap-northeast-1.compute.internal Ready <none> 99s v1.13.4-k3s.1 |
nginxを起動してみるテスト
テンプレート作成
nginx-deployment.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<span class="na">apiVersion</span><span class="pi">:</span> <span class="s">extensions/v1beta1</span> <span class="na">kind</span><span class="pi">:</span> <span class="s">Deployment</span> <span class="na">metadata</span><span class="pi">:</span> <span class="na">name</span><span class="pi">:</span> <span class="s">nginx</span> <span class="na">spec</span><span class="pi">:</span> <span class="na">replicas</span><span class="pi">:</span> <span class="m">1</span> <span class="na">template</span><span class="pi">:</span> <span class="na">metadata</span><span class="pi">:</span> <span class="na">labels</span><span class="pi">:</span> <span class="na">app</span><span class="pi">:</span> <span class="s">nginx</span> <span class="na">spec</span><span class="pi">:</span> <span class="na">containers</span><span class="pi">:</span> <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">nginx</span> <span class="na">image</span><span class="pi">:</span> <span class="s">nginx:1.7.5</span> <span class="na">ports</span><span class="pi">:</span> <span class="pi">-</span> <span class="na">containerPort</span><span class="pi">:</span> <span class="m">80</span> |
起動
1 |
k3s kubectl apply -f nginx-deployment.yaml |
サービスを定義
1 |
k3s kubectl expose deployment/nginx --type="NodePort" --port 80 |
ポートを確認
1 2 3 4 5 6 7 |
[root@ip-172-31-37-113 bin]# k3s kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 12m nginx NodePort 10.43.18.161 <none> 80:30845/TCP 47s |
ローカルからアクセス
1 2 3 4 5 |
[root@ip-172-31-37-113 bin]# curl -i http://localhost:30845 HTTP/1.1 200 OK Server: nginx/1.7.5 Date: Wed, 18 Sep 2019 02:25:19 GMT Content-Type: text/html |
リモートからアクセス
参考
https://tech-lab.sios.jp/archives/13564
https://qiita.com/lughshot/items/5f7165c1fc5b55779746