LoginSignup
1
1

More than 3 years have passed since last update.

ec2インスタンスでk3sを使う

Posted at

k3sとは

  • プチKubernetes
  • 超軽い 40MBくらい
  • k8sから5機能が削がれている
  • mac,windowsでは使用できず、Linuxだけ

環境

  • AWS EC2
  • Amazon Linux 2

k3sのインストール

yum -y install wget
cd /usr/local/bin/
wget https://github.com/rancher/k3s/releases/download/v0.2.0/k3s
chmod 755 ./k3s

起動

k3s server &

起動確認

# 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
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.5
        ports:
        - containerPort: 80

起動

k3s kubectl apply -f nginx-deployment.yaml

サービスを定義

k3s kubectl expose deployment/nginx --type="NodePort" --port 80

ポートを確認

[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

ローカルからアクセス

[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

リモートからアクセス

image.png

参考

https://tech-lab.sios.jp/archives/13564
https://qiita.com/lughshot/items/5f7165c1fc5b55779746

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1