Skip to content

Instantly share code, notes, and snippets.

@nagapavan
Created June 29, 2019 09:02
Show Gist options
  • Save nagapavan/3e9940ede0fdb67372976572558e03a6 to your computer and use it in GitHub Desktop.
Save nagapavan/3e9940ede0fdb67372976572558e03a6 to your computer and use it in GitHub Desktop.
Kubernetes command reference
### Base install
# yum remove -y docker docker-common docker-selinux docker-engine # Optional, use only to cleanup existin Docker
yum -y --nogpgcheck install docker-ce
systemctl daemon-reload;
systemctl enable docker
systemctl restart docker.service
### Setup Kubernetes
## Install Kubernetes
cat << EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
echo "Installing kubelet, kubeadm and kubectl"
yum install -y kubelet-1.9.3-0 kubeadm-1.9.3-0 kubectl-1.9.3-0
echo "Enable kubelet as system.d service"
systemctl enable kubelet
echo "Starting kubelet service ..."
systemctl start kubelet
## Initialize
sysctl --system
# yes | kubeadm reset # Only required if kubectl is already installed on the node
# Following CIDR is for Canal
kubeadm init --token-ttl 0 --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=all
kubeadm token create --ttl 0 --print-join-command
mkdir -p $HOME/.kube | true
yes | cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
yes | cp /etc/kubernetes/admin.conf $HOME/
chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf
## Configure additional components
# Calico CNI
kubectl apply -f https://docs.projectcalico.org/v3.7/manifests/calico.yaml
# Metrics components
kubectl create -f https://raw.githubusercontent.com/kubernetes/heapster/master/deploy/kube-config/influxdb/influxdb.yaml
kubectl create -f https://raw.githubusercontent.com/kubernetes/heapster/master/deploy/kube-config/influxdb/grafana.yaml
kubectl create -f https://raw.githubusercontent.com/kubernetes/heapster/master/deploy/kube-config/influxdb/heapster.yaml
kubectl create -f https://raw.githubusercontent.com/kubernetes/heapster/master/deploy/kube-config/rbac/heapster-rbac.yaml
# Dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
## On Slave Nodes
## Install Kubernetes
cat << EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
echo "Installing kubelet, kubeadm and kubectl"
yum install -y kubelet-1.9.3-0 kubeadm-1.9.3-0 kubectl-1.9.3-0
echo "Enable kubelet as system.d service"
systemctl enable kubelet
echo "Starting kubelet service ..."
systemctl start kubelet
## Join node to the master
kubeadm join --token %join_token% %join_ip% --discovery-token-ca-cert-hash %discovery_token%
systemctl daemon-reload
systemctl restart docker.service
systemctl restart kubelet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment