安裝 Kubernetes

注意事項

  • Volumes、External Load Balancers 只能在特定的雲端平台上使用

AWS Free tier

使用本機

// 關閉防火牆
# setenforce 0
# systemctl stop firewalld
# systemctl disable firewalld

// 增加kubernetes yum repo
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
EOF

// 安裝相關套件
yum install docker kubelet kubeadm kubectl kubernetes-cni -y

// 啟動Docker、K8s
systemctl enable docker
systemctl start docker
systemctl enable kubelet
systemctl start kubelet

// at master node
kubeadm init

// 跑完後記得記下以下內容
    You can now join any number of machines by running the following on each node:
    kubeadm join --token=da9646.60c02a85541104a0 10.128.0.2

// 安裝pod overlay network
kubectl apply -f https://git.io/weave-kube


// 在 work node
執行剛剛記下來指令內容
    # kubeadm join --token=da9646.60c02a85541104a0 10.128.0.2

// 在 maste node,確認以下資訊:

# kubectl get nodes
       NAME         STATUS           AGE
       k8s-master   Ready,master     17h
       k8s-node      Ready           17h

Minikube

  • 支援 Windos、Linux及 MacOS
minikube start

啟動

kubectl run hello-minikube --image-gcr... --poprt=8080
kubectl expose deployment hello-minikube --type=NodePart

minkube stop // 停止

建立 Containers

  • Dockerfile
FROM node:4.6
WORKDIR /app
ADD . /app
RUN npm install
EXPOSE 4567
CMD npm start
  • 建立映像檔(目錄下最少要有:Dockerfile、程式s、package.json)
cd myapp
docker build .