Skip to content

Latest commit

 

History

History
266 lines (199 loc) · 7.58 KB

pouch_with_kubernetes_deploying_aliyun.md

File metadata and controls

266 lines (199 loc) · 7.58 KB

Deploy Kubernetes With PouchContainer, Powered By Aliyun

Overview

This document shows how to easily install a Kubernetes cluster with PouchContainer as the container runtime using Aliyun Image Repository.

pouch_with_kubernetes

Restriction

Kubernetes: Version 1.5+ is recommanded.

NOTE: PouchContainer version prior to 0.5.x (including version 0.5.0) did not support configuring CNI network plugin with flannel. If you want to do that, use the latest code from the branch of master, refer to Developer Quick-Start

Install and Configure

An all-in-one kubernetes cluster with PouchContainer runtime could be deployed by running:

hack/kubernetes/allinone_aliyun.sh

Please refer to allinone_aliyun .

Install PouchContainer

You can easily setup a basic PouchContainer environment, see INSTALLATION.md.

Configure PouchContainer

On Ubuntu 16.04+:

NOTE:

  • If you'd like to use Kubernetes 1.10+, CRI_VERSION should be "v1alpha2"
  • If you'd like to use Kubernetes 1.11+, CONTAINERD_ADDR should be "/run/containerd/containerd.sock"
CRI_VERSION="v1alpha1"
CONTAINERD_ADDR="/var/run/containerd/containerd.sock"
sed -i 's/ExecStart=\/usr\/bin\/pouchd/ExecStart=\/usr\/bin\/pouchd --enable-cri=true --cri-version=${CRI_VERSION} --containerd=${CONTAINERD_ADDR}/g' /usr/lib/systemd/system/pouch.service
systemctl daemon-reload
systemctl restart pouch

On CentOS 7:

NOTE: If you'd like to use Kubernetes 1.10+, CRI_VERSION should be "v1alpha2"

CRI_VERSION="v1alpha1"
sed -i 's/ExecStart=\/usr\/local\/bin\/pouchd/ExecStart=\/usr\/local\/bin\/pouchd --enable-cri=true --cri-version=${CRI_VERSION}/g' /lib/systemd/system/pouch.service
systemctl daemon-reload
systemctl restart pouch

Setup Repo

On CentOS 7:

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

Install Kubernetes Components

On Ubuntu 16.04+:

RELEASE="v1.9.4"
KUBE_URL="https://storage.googleapis.com/kubernetes-release/release/${RELEASE_UBUNTU}/bin/linux/amd64"
wget "${KUBE_URL}/kubeadm" -O /usr/bin/kubeadm
wget "${KUBE_URL}/kubelet" -O /usr/bin/kubelet
wget "${KUBE_URL}/kubectl" -O /usr/bin/kubectl
chmod +x /usr/bin/kubeadm /usr/bin/kubelet /usr/bin/kubectl

KUBELET_URL="https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE_UBUNTU}/build/debs"
mkdir -p /etc/systemd/system/kubelet.service.d
wget "${KUBELET_URL}/kubelet.service" -O /etc/systemd/system/kubelet.service
wget "${KUBELET_URL}/10-kubeadm.conf" -O /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

On CentOS 7:

RELEASE="1.9.4-0.x86_64"
yum -y install kubelet-${RELEASE} kubeadm-${RELEASE} kubectl-${RELEASE}

For more details, please check install kubelet.

Install CNI

On Ubuntu 16.04+:

CNI_VERSION="v0.6.0"
mkdir -p /opt/cni/bin
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz

On CentOS 7:

setenforce 0
yum install -y kubernetes-cni

Using custom configurations

Configure kubelet with PouchContainer as its runtime:

cat <<EOF > /etc/systemd/system/kubelet.service.d/0-pouch.conf
[Service]
Environment="KUBELET_EXTRA_ARGS=--container-runtime=remote --container-runtime-endpoint=unix:///var/run/pouchcri.sock --image-service-endpoint=unix:///var/run/pouchcri.sock"
EOF

sudo systemctl daemon-reload

Using custom ImageRepository

# cat kubeadm.conf
apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
kubernetesVersion: stable-1.9
networking:
  podSubnet: 10.244.0.0/16

For more details, please check kubeadm init.

Setting up the master node

For more detailed Kubernetes cluster installation, please check Using kubeadm to Create a Cluster

kubeadm init --config kubeadm.conf --ignore-preflight-errors=all

To start using your cluster, you need to run the following as a regular user:

mkdir -p ~/.kube
sudo cp -i /etc/kubernetes/admin.conf  ~/.kube/config
sudo chown $(id -u):$(id -g) ~/.kube/config

Configure CNI network plugin with flannel

kubectl create -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml

NOTE: For other plugins, please check Installing a pod network.

Optional: enable schedule pods on the master node

kubectl taint nodes --all node-role.kubernetes.io/master:NoSchedule-

Setting up the minion nodes

After initializing the master node, you may get the following prompt:

You can now join any number of machines by running the following on each node
as root:

  kubeadm join --token $token ${master_ip:port} --discovery-token-ca-cert-hash $ca-cert

NOTE: Because kubeadm still assumes docker as the only container runtime ,Use the flag --ignore-preflight-errors=all to skip the check.

Copy & Run it in all your minion nodes.

Run and Verify

Create a deployment named Pouch:

# cat pouch.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pouch
  labels:
    pouch: pouch
spec:
  selector:
    matchLabels:
      pouch: pouch
  template:
    metadata:
      labels:
        pouch: pouch
    spec:
      containers:
      - name: pouch
        image: docker.io/library/nginx:latest
        ports:
        - containerPort: 80

# kubectl create -f pouch.yaml
deployment "pouch" created

Confirm the pod of deployment is really running:

# kubectl get pods -o wide
NAME                     READY     STATUS    RESTARTS   AGE       IP           NODE
pouch-7dcd875d69-gq5r9   1/1       Running   0          44m       10.244.1.4   master
# curl 10.244.1.4
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>