• Stars
    star
    414
  • Rank 104,550 (Top 3 %)
  • Language
  • License
    MIT License
  • Created over 6 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Goto Kubernetes

Goto Kubernetes

github workflow

安装 Kubernetes

对于 Mac 用户可以参考: k8s-docker-desktop-for-mac, 通过 Docker Desktop for Mac 开启和使用 Kubernetes

  1. 安装Docker
$ curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
  1. 安装 kubeadm, kubelet and kubectl

# root(sudo -i)

# Debian/Ubuntu
apt-get update && apt-get install -y apt-transport-https
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl

# CentOS/RHEL/Fedora
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
yum install -y kubelet kubeadm kubectl
  1. 使用 kubeadm 创建 Kubernetes 集群
# 确保关闭交换空间(running with swap on is not supported. Please disable swap)
$ sudo swapoff -a
# 永久关闭需要编辑 `/etc/fstab` 注释掉 `swap` 所在行

# 获取最新 Kubernetes 版本号
$ KUBERNETES_RELEASE_VERSION="$(curl -sSL https://dl.k8s.io/release/stable.txt)"

# 可以用下面的命令列出 kubeadm 需要的 images
$ kubeadm config images list --kubernetes-version=${KUBERNETES_RELEASE_VERSION}
# 提前拉取所需的镜像
$ docker pull gotok8s/coredns:v1.8.6 && docker tag gotok8s/coredns:v1.8.6 gotok8s/coredns/coredns:v1.8.6
$ kubeadm config images pull --config init.yml

# 集群初始化(init.yml文件中配置了使用阿里的镜像仓库)
$ sudo kubeadm init --config init.yml
# 或者执行(忽略Docker版本检查)
$ sudo kubeadm init --config init.yml --ignore-preflight-errors=SystemVerification

# KUBECONFIG 设置
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

# 使用 `flannel` 网络
$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

# Master Isolation (if single-machine Kubernetes cluster )
$ kubectl taint nodes --all node-role.kubernetes.io/master-

Kubernetes Dashboard

部署 Kubernetes Dashboard

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended.yaml

# 开启本机访问代理
$ kubectl proxy

创建Dashboard管理员用户并用token登陆

# 创建 ServiceAccount kubernetes-dashboard-admin 并绑定集群管理员权限
$ kubectl apply -f https://raw.githubusercontent.com/gotok8s/gotok8s/master/dashboard-admin.yaml

# 获取登陆 token
$ kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep kubernetes-dashboard-admin | awk '{print $1}')

通过下面的连接访问 Dashboard: http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

输入上一步获取的token, 验证并登陆。

Helm

安装

详细使用说明请参考 Helm官方文档

# Linux 用户
$ curl -s https://get.helm.sh/helm-v3.8.1-linux-amd64.tar.gz | tar xzv
$ sudo cp linux-amd64/helm /usr/local/bin
$ rm -rf linux-amd64

# Mac 用户
$ brew install helm

使用

# 添加 charts repo
$ helm repo add bitnami https://charts.bitnami.com/bitnami

# 测试安装 redis chart
$ helm install my-redis bitnami/redis

# 删除 redis
$ helm uninstall my-redis

NGINX Ingress

# install by helm
$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
$ helm repo update

$ helm install ingress-nginx ingress-nginx/ingress-nginx

Istio

下载并安装 Istio

$ curl -L https://istio.io/downloadIstio | sh -
# 进入下载的文件夹,这里以 `istio-1.9.0` 为例
$ cd istio-1.11.4
$ export PATH=$PWD/bin:$PATH
# 安装
$ istioctl install --set profile=demo -y
# 设置自动注入 Envoy sidecar proxies
$ kubectl label namespace default istio-injection=enabled

部署示例

# 部署
$ kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
# 查看示例返回
$ kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"

升级 Kubernetes 版本

# 修改 `init.yml` 中 `kubernetesVersion` 版本号, 执行
sudo kubeadm upgrade apply --config init.yml --ignore-preflight-errors=SystemVerification