# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
. restart-codekube.sh
#!/bin/bash
kubectl get pods "$HOSTNAME" || (
echo "Use kubens to switch to the namespace of this instance and try again!"
echo "(we can't do this for you since we don't know the namespace name)"
exit 1
)
kubectl delete pod "$HOSTNAME"
. code.sh
#!/bin/bash
# Script that mimics the open-from-stdin functionality of VSCode
if [ "$1" == "-" ]; then
TEMP=$(mktemp /tmp/stdin_XXXXXX)
cat > "$TEMP"
exec code-server -r "$TEMP"
exit 0
fi;
# Pass through everything else to `code-server`
# Shellcheck SC2068 = quoting variables to prevent globbing - we want that here.
# shellcheck disable=SC2068
exec code-server $@
. startup.sh
#!/bin/bash
[[ -f /home/code/.homedir-initialized ]] || (
echo "Remove this file to re-copy files from /etc/skel /opt/default_home at next container startup" > /home/code/.homedir-initialized
# dotglob to catch files like `.bashrc`
shopt -s dotglob
cp -r /etc/skel/* /home/code
cp -r /opt/default_home/* /home/code
shopt -u dotglob
# install kubernetes ext
#su code --login -c "/usr/bin/code-server --install-extension ms-kubernetes-tools.vscode-kubernetes-tools"
)
# make workspace dir if it doesn't exist
[[ -d /home/code/workspace ]] || mkdir /home/code/workspace
# chown stuff to kube:kube
chown code:code /home/code -R
# generate env whitelist from su using.. a blacklist, pretty much.
env_whitelist=$(env | cut -d = -f 1 | grep -v -e HOSTNAME -e PWD -e HOME -e TERM -e SHLVL -e LC_ALL -e ^_$ | tr "\n" "," | head -c -1)
# configure kubectl so vscode's kubernetes extension works
# su code --login -w "$env_whitelist" -c "/usr/local/bin/generate-kubeconfig.sh"
# start code-server
# su code --login -w "$env_whitelist" -c "/usr/bin/code-server --bind-addr 0.0.0.0:8080 /home/code/workspace" # --enable-proposed-api [\"ms-vsliveshare.vsliveshare\",\"ms-vscode.node-debug\",\"ms-vscode.node-debug2\"]
runuser code --login -w "$env_whitelist" -c "/usr/bin/code-server --bind-addr 0.0.0.0:8080 /home/code/workspace" # --enable-proposed-api [\"ms-vsliveshare.vsliveshare\",\"ms-vscode.node-debug\",\"ms-vscode.node-debug2\"]
2. 설명
① Ubuntu 20.04를 기준으로 했다.
. 18.04도 가능할 것으로 보이지만, `startup.sh` 내용 中 마지막 라인에 있는
. `su` 또는 `runuser`의 `-w` 옵션이 18.04에서는 적용되지 않아서 지금은 20.04로 했다.
→ 18.04에서도 적용 가능하도록 연구해보겠다 (언제가 될지는...^^)
② 개발환경으로 사용되기에 기본적인 패키지들을 설치했다.
. 추후 필요에 따라 추가하면 된다.
. `DEBIAN_FRONTEND="noninteractive"` 부분이 없으면 설치 중간에 사용자 입력을 기다리기도 한다. (설치 오류)
master$ kubectl cluster-info Kubernetes control plane is running at https://127.0.0.1:6443
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
master$ kubectl get nodes NAME STATUS ROLES AGE VERSION node1 Ready control-plane,master 14m v1.20.7 node2 NotReady <none> 13m v1.20.7 node3 NotReady <none> 13m v1.20.7
- Vagrant 사용을 위해서는 제일 먼저 작업을 실행할 Directory를 하나 만들어야 한다.
- Workspace 하나 만든다고 생각하면 될 것 같다.
> mkdir vagrant-hello
디렉터리: C:\Users\whatw\workspace
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2021-07-14 오후 2:00 vagrant-hello
> cd .\vagrant-hello\
02. init
- Workspace 안에서 init 작업을 하면 된다.
- `init` 뒤에는 사용할 이미지 주소를 적어주면 된다.
> vagrant init whatwant/Ubuntu-20.04-Server
==> vagrant: A new version of Vagrant is available: 2.2.17 (installed version: 2.2.16)!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
> dir
디렉터리: C:\Users\whatw\workspace\vagrant-hello
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2021-07-14 오후 2:04 3104 Vagrantfile
03. check Vagrantfile
- `init`을 하면 `Vagrantfile`을 생성해준다.
- 첫 줄을 보면 알겠지만, ruby 포맷이다..... ㅠㅜ
# -*- mode: ruby -*-
# vi: set ft=ruby :
# 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 = "whatwant/Ubuntu-20.04-Server"
# 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
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
end
04. check IP
- 이 부분은 필요하신 분들만 선택적으로 하면 된다.
- Why : 이 부분을 진행하는 이유는 다음과 같다.
. 집에서 공유기를 사용하고 있음
. VirtualBox에서 Ubuntu를 여러개를 실행할 계획인데,
. 서로 간의 통신을 구성하기 위해서 각 Ubuntu의 IP를 고정하고 싶음
- 공유기에서 비어있는 IP를 확인해놓자
- 각자의 공유기에 따라 관리 페이지 들어가서 현재 할당되어 있는 IP 내역 확인하고,
- 나중에 MAC 주소에 따른 IP 할당 설정을 해보자.
05. edit Vagrant
- 리소스 포함해서 원하는 VM 모습으로 설정해보자
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "whatwant/Ubuntu-20.04-Server"
config.vm.box_version = "0.1.0"
config.vm.network "public_network", ip: "192.168.100.201"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.cpus = "2"
vb.memory = "2048"
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get upgrade -y
SHELL
end
06. Vagrant Up
- 실행해보자 !!
> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'whatwant/Ubuntu-20.04-Server'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'whatwant/Ubuntu-20.04-Server' version '0.1.0' is up to date...
==> default: Setting the name of the VM: vagrant-hello_default_1626272864694_38723
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => C:/Users/whatw/workspace/vagrant-hello
==> default: Running provisioner: shell...
default: Running: inline script
default: Hit:1 http://kr.archive.ubuntu.com/ubuntu focal InRelease
default: Get:2 http://kr.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
default: Get:3 http://kr.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
default: Get:4 http://kr.archive.ubuntu.com/ubuntu focal-security InRelease [114 kB]
default: Get:5 http://kr.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,086 kB]
default: Get:6 http://kr.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [239 kB]
default: Get:7 http://kr.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [13.8 kB]
default: Get:8 http://kr.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [841 kB]
default: Get:9 http://kr.archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [176 kB]
default: Get:10 http://kr.archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [18.3 kB]
default: Get:11 http://kr.archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [5,792 B]
default: Get:12 http://kr.archive.ubuntu.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [288 B]
default: Get:13 http://kr.archive.ubuntu.com/ubuntu focal-security/main amd64 Packages [745 kB]
default: Get:14 http://kr.archive.ubuntu.com/ubuntu focal-security/main Translation-en [148 kB]
default: Get:15 http://kr.archive.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [8,036 B]
default: Get:16 http://kr.archive.ubuntu.com/ubuntu focal-security/universe amd64 Packages [629 kB]
default: Get:17 http://kr.archive.ubuntu.com/ubuntu focal-security/universe Translation-en [96.2 kB]
default: Get:18 http://kr.archive.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [11.6 kB]
default: Fetched 4,346 kB in 13s (322 kB/s)
default: Reading package lists...
default: Reading package lists...
default: Building dependency tree...
default:
default: Reading state information...
default: Calculating upgrade...
default: The following packages will be upgraded:
default: libuv1 linux-base
default: 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
default: 1 standard security update
default: Need to get 98.5 kB of archives.
default: After this operation, 0 B of additional disk space will be used.
default: Get:1 http://kr.archive.ubuntu.com/ubuntu focal-updates/main amd64 libuv1 amd64 1.34.2-1ubuntu1.3 [80.8 kB]
default: Get:2 http://kr.archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-base all 4.5ubuntu3.6 [17.8 kB]
default: dpkg-preconfigure: unable to re-open stdin: No such file or directory
default: Fetched 98.5 kB in 1s (73.4 kB/s)
default: (Reading database ...
(Reading database ... 45%abase ... 5%
(Reading database ... 55%abase ... 50%
default: (Reading database ... 60%
default: (Reading database ... 65%
default: (Reading database ... 70%
default: (Reading database ... 75%
default: (Reading database ... 80%
default: (Reading database ... 85%
default: (Reading database ... 90%
default: (Reading database ... 95%
(Reading database ... 145156 files and directories currently installed.)
default: Preparing to unpack .../libuv1_1.34.2-1ubuntu1.3_amd64.deb ...
default: Unpacking libuv1:amd64 (1.34.2-1ubuntu1.3) over (1.34.2-1ubuntu1.1) ...
default: Preparing to unpack .../linux-base_4.5ubuntu3.6_all.deb ...
default: Unpacking linux-base (4.5ubuntu3.6) over (4.5ubuntu3.5) ...
default: Setting up linux-base (4.5ubuntu3.6) ...
default: Setting up libuv1:amd64 (1.34.2-1ubuntu1.3) ...
default: Processing triggers for man-db (2.9.1-1) ...
default: Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
- `Vagrantfile`에서 `vb.gui = false` 설정을 했기에, `VirtualBox`가 별도 실행되지 않는다.
- 직접 `VirtualBox`를 실행해보면 다음과 같이 새로 머신이 하나 추가된 것을 볼 수 있다.
- 머신 이름은 새로 생성한 Workspace(Directory) 이름 + 별칭 + 랜덤 숫자 ...
- 머신을 더블 클릭하면 실행된 머신이 나타난다
- 로그인 ID / Password는 모두 `vagrant`
07. status
- 현재 `Vagrant`의 상태를 확인해보자.
- 사용할 수 있는 명령어도 친절히 알려준다.
> vagrant status
Current machine states:
default running (virtualbox)
The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.