Search
Duplicate
📒

[Kubernetes Infra] 01-2. 쿠버네티스 설치

상태
완료
수업
Kubernetes Infra
주제
연관 노트
3 more properties
참고

쿠버네티스 경량화 설치 방법

NOTE
쿠버네티스를 운영환경에 설치하기 위해선 최소 3대의 마스터 서버와, 컨테이너 배포를 위한 n개의 노드 서버가 필요하다!
기존 방식은 복잡한 설정이 필요하다. (배우기 적합하지 않음)
학습을 위해 마스터와 노드를 하나의 서버에 손쉽게 관리할 수 있는 방식을 설치한다.

주의

개발환경과 운영환경의 가장 큰 차이점은 개발 환경은 단일 노드로 여러 노드에 스케쥴링 하는 테스트가 어렵다.
LoadBalancerPersistent Local Storage또한 가상으로 만들어야 하므로, 실습을 정확하게 하려면 운영환경(멀티노드)에서 진행하자

minikube

NOTE
로컬 환경에서 쿠버네티스 클러스터를 단일 노드로 실행하기 위한 도구!
# 버전확인 minikube version # virtualbox이외에 다른 드라이버 사용 가능 minikube start --driver=virtualbox minikube start --driver=hyperv # 상태확인 minikube status # 정지 minikube stop # 삭제 minikube delete # ssh 접속 minikube ssh # ip 확인 minikube ip
Bash
복사

k3s

NOTE
minikube를 사용할 수 없거나 네트워크등 여러가지 이슈로 실습이 어려운 경우, 별도 클라우드 서버에 k3s를 설치하여 원격으로 실습할 수 있다.
경량회된 k8s이지만 Master/Worker Node에 있을 건 다 있다.
차이점은 .etcd를 사용하지 않고 sqlite를 사용하는 것
curl -sfL https://get.k3s.io | sh - sudo chown ubuntu:ubuntu /etc/rancher/k3s/k3s.yaml # 확인 kubectl get nodes # 설정 복사 cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
Bash
복사
설치코드 (우분투 환경)

쿠버네티스 설치 방법

NOTE
쿠버네티스를 운영환경에 설치하기 위해선 최소 3대의 마스터 서버와, 컨테이너 배포를 위한 n개의 노드 서버가 필요하다!
# -*- mode: ruby -*- # vi:set ft=ruby sw=2 ts=2 sts=2: # Define the number of master and worker nodes # If this number is changed, remember to update setup-hosts.sh script with the new hosts IP details in /etc/hosts of each VM. NUM_WORKER_NODE = 2 IP_NW = "192.168.56." MASTER_IP_START = 11 NODE_IP_START = 20 # Sets up hosts file and DNS def setup_dns(node) # Set up /etc/hosts node.vm.provision "setup-hosts", :type => "shell", :path => "ubuntu/vagrant/setup-hosts.sh" do |s| s.args = ["enp0s8", node.vm.hostname] end # Set up DNS resolution node.vm.provision "setup-dns", type: "shell", :path => "ubuntu/update-dns.sh" end # Runs provisioning steps that are required by masters and workers def provision_kubernetes_node(node) # Set up DNS setup_dns node # Set up ssh node.vm.provision "setup-ssh", :type => "shell", :path => "ubuntu/ssh.sh" end # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure("2") do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. # config.vm.box = "base" config.vm.box = "ubuntu/jammy64" config.vm.boot_timeout = 900 # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. config.vm.box_check_update = false # Provision Master Nodes config.vm.define "kubemaster" do |node| # Name shown in the GUI node.vm.provider "virtualbox" do |vb| vb.name = "kubemaster" vb.memory = 3072 vb.cpus = 2 end node.vm.hostname = "kubemaster" node.vm.network :private_network, ip: IP_NW + "#{MASTER_IP_START}" node.vm.network "forwarded_port", guest: 22, host: "#{2710}" provision_kubernetes_node node # Install (opinionated) configs for vim and tmux on master-1. These used by the author for CKA exam. node.vm.provision "file", source: "./ubuntu/tmux.conf", destination: "$HOME/.tmux.conf" node.vm.provision "file", source: "./ubuntu/vimrc", destination: "$HOME/.vimrc" end # Provision Worker Nodes (1..NUM_WORKER_NODE).each do |i| config.vm.define "kubenode0#{i}" do |node| node.vm.provider "virtualbox" do |vb| vb.name = "kubenode0#{i}" vb.memory = 2048 vb.cpus = 1 end node.vm.hostname = "kubenode0#{i}" node.vm.network :private_network, ip: IP_NW + "#{NODE_IP_START + i}" node.vm.network "forwarded_port", guest: 22, host: "#{2720 + i}" provision_kubernetes_node node end end end
Ruby
복사