Skip to content

Commit

Permalink
install
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Apr 15, 2020
1 parent 88a7e31 commit 06d0623
Show file tree
Hide file tree
Showing 14 changed files with 741 additions and 0 deletions.
42 changes: 42 additions & 0 deletions install/End-End Tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Run a simple nginx deployment:

kubectl run nginx --image=nginx
View the deployments in your cluster:

kubectl get deployments
View the pods in the cluster:

kubectl get pods
Use port forwarding to access a pod directly:

kubectl port-forward $pod_name 8081:80
Get a response from the nginx pod directly:

curl --head http://127.0.0.1:8081
View the logs from a pod:

kubectl logs $pod_name
Run a command directly from the container:

kubectl exec -it $pod_name -- nginx -v
Create a service by exposing port 80 of the nginx deployment:

kubectl expose deployment nginx --port 80 --type NodePort
List the services in your cluster:

kubectl get services
Get a response from the service:

curl -I localhost:$node_port
List the nodes' status:

kubectl get nodes
View detailed information about the nodes:

kubectl describe nodes
View detailed information about the pods:

kubectl describe pods


All Kube Commands: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-strong-getting-started-strong-
88 changes: 88 additions & 0 deletions install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
## Install Kubernets on Ubuntu 18.04 LTS

### Step1: `On All Machines ( Master & All nodes ):`

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update ; clear
sudo apt-get install -y docker-ce
sudo service docker start ; clear

echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update ; clear
sudo apt-get install -y kubelet kubeadm kubectl

### Step2: `On Master only:`

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

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

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml

kubectl get nodes
kubectl get all --all-namespaces

### Step3: `On Nodes only:`
copy the kubeadm join token from master & run it on all nodes
Ex: kubeadm join 10.128.15.231:6443 --token mks3y2.v03tyyru0gy12mbt \
--discovery-token-ca-cert-hash sha256:3de23d42c7002be0893339fbe558ee75e14399e11f22e3f0b34351077b7c4b56


## Install K8s: CentOS WITH 2 CPUS & 4GB RAM

### Step1: `On All Machines ( Master & All nodes ):`

### Set SELinux in permissive mode (effectively disabling it)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

### Install Docker
sudo yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine docker-ce docker-ce-cli containerd.io
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
systemctl enable --now docker
systemctl start docker

### Install kubeadm,kubelet,kubectl
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

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet

### Step2: `On Master only:`

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

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

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml

kubectl get nodes
kubectl get all --all-namespaces

### Step3: `On Nodes only:`

copy the kubeadm join token from master & run it on all nodes

Ex: kubeadm join 10.128.15.231:6443 --token mks3y2.v03tyyru0gy12mbt \
--discovery-token-ca-cert-hash sha256:3de23d42c7002be0893339fbe558ee75e14399e11f22e3f0b34351077b7c4b56
29 changes: 29 additions & 0 deletions install/backup-cluster.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Backing up your cluster can be a useful exercise, especially if you have a single etcd cluster, as all the cluster state is stored there. The etcdctl utility allows us to easily create a snapshot of our cluster state (etcd) and save this to an external location. In this lesson, we’ll go through creating the snapshot and talk about restoring in the event of failure.


Get the etcd binaries:
wget https://github.com/etcd-io/etcd/releases/download/v3.3.12/etcd-v3.3.12-linux-amd64.tar.gz

Unzip the compressed binaries:
tar xvf etcd-v3.3.12-linux-amd64.tar.gz

Move the files into /usr/local/bin:
sudo mv etcd-v3.3.12-linux-amd64/etcd* /usr/local/bin

Take a snapshot of the etcd datastore using etcdctl:
sudo ETCDCTL_API=3 etcdctl snapshot save snapshot.db --cacert /etc/kubernetes/pki/etcd/server.crt --cert /etc/kubernetes/pki/etcd/ca.crt --key /etc/kubernetes/pki/etcd/ca.key

View the help page for etcdctl:
ETCDCTL_API=3 etcdctl --help

Browse to the folder that contains the certificate files:
ls /etc/kubernetes/pki/etcd/
cd

View that the snapshot was successful:
ETCDCTL_API=3 etcdctl --write-out=table snapshot status snapshot.db

Zip up the contents of the etcd directory:
sudo tar -zcvf etcd.tar.gz /etc/kubernetes/pki/etcd

Copy the etcd directory to another server:
78 changes: 78 additions & 0 deletions install/bootstrap-cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## Calico pod network
```
sudo kubeadm init
Note: note down the kubeadm join command
sudo mkdir -p $HOME/.kube
sudo rm $HOME/.kube/config
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
sudo kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/calico.yaml
```
## how to find kubeadm join token later
```
token=`kubeadm token generate`
kubeadm token create "$token" --print-join-command --ttl=0
```
















































## Flannel pod network
```
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
sudo mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
make note of kubeadm join command to be run on Nodes
for coredns pods to come up run below
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml
```
11 changes: 11 additions & 0 deletions install/cluster-api-info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kubectl get all --all-namespaces

kubectl api-resources
kubectl api-resources --namespaced=true # All namespaced resources
kubectl api-resources --namespaced=false # All non-namespaced resources
kubectl api-resources -o name # All resources with simple output (just the resource name)
kubectl api-resources -o wide # All resources with expanded (aka "wide") output
kubectl api-resources --verbs=list,get # All resources that support the "list" and "get" request verbs
kubectl api-resources --api-group=extensions # All resources in the "extensions" API group
kubectl api-versions # List api group
kubectl explain resourcename . # kubectl explain pod
19 changes: 19 additions & 0 deletions install/config-locations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/etc/kubernetes/ # Config folder
/etc/kubernetes/pki/ # Certificate files
/etc/kubernetes/kubelet.conf # Credentials to API server
/etc/kubernetes/admin.conf # Superuser credentials
~/.kube/config # kubectl config file
/var/lib/kubelet/ # Kubernets working dir
/var/lib/docker/, /var/log/containers/ # Docker working dir
/var/lib/etcd/ # Etcd working dir
/etc/cni/net.d/ # Network cni
/var/log/pods/ # Log files
/etc/systemd/system/kubelet.service.d/10-kubeadm.conf # Env
export KUBECONFIG=/etc/kubernetes/admin.conf # Env
/lib/systemd/system/kubelet.service # systemd unit file for kubelet
/lib/systemd/system/docker.service # systemd unit file for docker



journalctl -u kubelet # to view the kubelet logs
journalctl -u kube-proxy
38 changes: 38 additions & 0 deletions install/install-k8s-centos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Install K8s: CentOS 18 LTS WITH 2 CPUS & 4GB RAM

### Install Docker

`sudo yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine docker-ce docker-ce-cli containerd.io`

`sudo yum install -y yum-utils device-mapper-persistent-data lvm2`

`sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo`

`sudo yum install -y docker-ce docker-ce-cli containerd.io`

`systemctl enable --now docker`

`systemctl start docker`

### Install kubeadm,kubelet,kubectl

```
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
```
##### Set SELinux in permissive mode (effectively disabling it)

`setenforce 0`

`sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config`

`yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes`

`systemctl enable --now kubelet`
49 changes: 49 additions & 0 deletions install/install-k8s-centos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

#### Remove if a cluster is already running
sudo kubeadm reset -f
sleep 30

#### Remove any pre installed docker packages
sudo yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine docker-ce docker-ce-cli containerd.io
cd /var/lib
sudo rm -r docker

#### Install Specific Docker version
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
if [ $? -eq 0 ];then
echo "docker-ce-$version is successfully installed"
else
echo "issue with docker-ce installation - process abort"
exit 1
fi
sudo systemctl enable --now docker
sudo systemctl start docker
echo " "

sudo yum remove -y kubeadm kubelet kubectl
#### Install Kubernetes latest components
echo "starting the installation of k8s components (kubeadm,kubelet,kubectl) ...."
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

sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
sudo systemctl enable --now kubelet
if [ $? -eq 0 ];then
echo "kubelet, kubeadm & kubectl are successfully installed"
else
echo "issue in installing kubelet, kubeadm & kubectl - process abort"
exit 2
fi
echo " "
Loading

0 comments on commit 06d0623

Please sign in to comment.