server setup for kubernetiess
1: Docker & Minikube
Step 1: Install Docker
1).
dnf update -y2).
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo3).
dnf install docker-ce --nobest -y4).
systemctl start docker5).
systemctl enable docker6).
docker -v
Step 2: Install Kubectl
1).
dnf install curl conntrack -y2).
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s
https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl3).
chmod +x ./kubectl4).
mv ./kubectl /usr/local/bin/kubectl5).
kubectl version --client
Step 3: Install Minikube
1).
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd642).
chmod +x minikube3).
install minikube /usr/local/bin/4).
minikube start --driver=none
#minikube start --driver=none --kubernetes-version v1.21.0
#minikube start --addons=ingress --cpus=2 --cni=flannel --install-addons=true --kubernetes-version=stable --memory=6g5).
minikube status5).output:
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured6).
kubectl cluster-info6).output:
Kubernetes master is running at https://your-server-ip:8443
KubeDNS is running at https://your-server-ip:8443/api/v1/namespaces/kube-system/services/kube-
dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.7).
kubectl get nodes
Step 4: Verify Kubernetes Cluster
1).
kubectl create deployment test-minikube --image=k8s.gcr.io/echoserver:1.102).
kubectl expose deployment test-minikube --type=NodePort --port=80803).
kubectl get pod4).
minikube service test-minikube --url
Step 5 : Enable Kubernetes Dashboard
1).
minikube addons list2).
minikube dashboard --url
[Expose]
This way of accessing Dashboard is only recommended for development environments in a single node setup.
Edit kubernetes-dashboard
service.
kubectl -n kubernetes-dashboard edit service kubernetes-dashboard
You should see yaml
representation of the service. Change type: ClusterIP
to type: NodePort
and save file. If it's already changed go to next step.
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
...
name: kubernetes-dashboard
namespace: kubernetes-dashboard
resourceVersion: "343478"
selfLink: /api/v1/namespaces/kubernetes-dashboard/services/kubernetes-dashboard
uid: 8e48f478-993d-11e7-87e0-901b0e532516
spec:
clusterIP: 10.100.124.90
externalTrafficPolicy: Cluster
ports:
- port: 443
protocol: TCP
targetPort: 8443
selector:
k8s-app: kubernetes-dashboard
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
Next we need to check port on which Dashboard was exposed.
kubectl -n kubernetes-dashboard get service kubernetes-dashboard
The output is similar to this:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes-dashboard NodePort 10.100.124.90 <nodes> 443:31707/TCP 21h
Dashboard has been exposed on port 31707 (HTTPS)
. Now you can access it from your browser at: https://<master-ip>:31707
. master-ip
can be found by executing kubectl cluster-info
. Usually it is either 127.0.0.1
or IP of your machine, assuming that your cluster is running directly on the machine, on which these commands are executed.
In case you are trying to expose Dashboard using NodePort
on a multi-node cluster, then you have to find out IP of the node on which Dashboard is running to access it. Instead of accessing https://<master-ip>:<nodePort>
you should access https://<node-ip>:<nodePort>
.
2: Install Jenkins
Dockerfile
FROM jenkinsci/jenkins:lts# Running as root to have an easy support for Docker
USER root# A default admin user
ENV ADMIN_USER=admin \
ADMIN_PASSWORD=password# Jenkins init scripts
COPY security.groovy /usr/share/jenkins/ref/init.groovy.d/# Install plugins at Docker image build time
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/install-plugins.sh $(cat /usr/share/jenkins/plugins.txt) && \
mkdir -p /usr/share/jenkins/ref/ && \
echo lts > /usr/share/jenkins/ref/jenkins.install.UpgradeWizard.state && \
echo lts > /usr/share/jenkins/ref/jenkins.install.InstallUtil.lastExecVersion# Install Docker
RUN apt-get -qq update && \
apt-get -qq -y install curl && \
curl -sSL https://get.docker.com/ | sh# Install Maven
RUN curl -LO https://www-eu.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz && \
tar xzf apache-maven-3.6.0-bin.tar.gz && \
mv ./apache-maven-3.6.0 /opt/apache-maven | sh
ENV PATH=/opt/apache-maven/bin:$PATH
ENV _JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true# Install kubectl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \
chmod +x ./kubectl && \
mv ./kubectl /usr/local/bin/kubectl | bash
$ docker build -t phayao/jenkins-k8s:lts .
$ docker push phayao/jenkins-k8s:lts
Jenkins บน Minikube
jenkins-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-k8s-claim
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 2Gi
storageClassName: standard
jenkins-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-k8s-deployment
labels:
app: jenkins-k8s
spec:
replicas: 1
selector:
matchLabels:
app: jenkins-k8s
template:
metadata:
labels:
app: jenkins-k8s
spec:
containers:
- name: jenkins-k8s
image: phayao/jenkins-k8s:lts
imagePullPolicy: Always
ports:
- containerPort: 8080
volumeMounts:
- name: docker-sock-volume
mountPath: /var/run/docker.sock
- name: jenkins-home
mountPath: "/var/jenkins_home"
volumes:
- name: jenkins-home
persistentVolumeClaim:
claimName: jenkins-k8s-claim
- name: docker-sock-volume
hostPath:
path: /var/run/docker.sock
jenkins-service.yml
apiVersion: v1
kind: Service
metadata:
name: jenkins-k8s-service
spec:
type: NodePort
selector:
app: jenkins-k8s
ports:
- protocol: TCP
port: 8080
targetPort: 8080$ kubectl create -f jenkins-pvc.yml
persistentvolumeclaim/jenkins-k8s-claim create$ kubectl create -f jenkins-deployment.yml
deployment.apps/jenkins-k8s-deployment created$ kubectl create -f jenkins-service.yml
service/jenkins-k8s-service created$ kubectl get deployment
$ kubectl get service
$ kubectl get pvc
user: admin / password: password
$ kubectl create -f fabric8-rbac.yml
fabric8-rbac.yml
#apiVersion: rbac.authorization.k8s.io/v1beta1apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: fabric8-rbac
subjects:
- kind: ServiceAccount
name: default
namespace: default
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
Done!
3: Install ingress
minikube addons enable ingress
Ref: https://kubernetes.io/docs/concepts/services-networking/ingress/
4: Setup SSL
apiVersion: cert-manager.io/v1alpha2kind: Certificatemetadata:name: healthcheck-api-selfsigned-crtspec:secretName: healthcheck-api-tls-secretissuerRef:kind: Issuername: selfsignedcommonName: "xxxx-api.xxxx.com"dnsNames:- "xxxx-api.xxxx.com"---apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata:name: healthcheck-api-ingressannotations:kubernetes.io/ingress.class: "nginx"nginx.ingress.kubernetes.io/rewrite-target: /spec:tls:- hosts:- "xxxx-api.xxxx.com"secretName: healthcheck-api-tls-secretrules:- host: xxxx-api.xxxx.comhttp:paths:- backend:serviceName: healthcheck-serviceservicePort: 80
5: Restart minikube and network after reboot
minikube start - driver=none
6: Install ward dashboard server monitoring
Build for Docker1. Clone https://github.com/B-Software/Ward.git
2. docker build --tag ward .
3. docker run --rm -it -d --name ward -p 4000:4000 -p 4001:4001 --privileged ward
4. Go to localhost:4000 in web browser, input the same application port
5. If you get error after being redirected to application port try hitting refresh
Done!
https://www.fosstechnix.com/how-to-install-minikube-on-ubuntu-22-04-lts/