Thank you for reading this post, don't forget to subscribe!
- Ставим docker.
- Отключаем swap (не забываем удалять и в /etc/fstab)
следующие команды можно тупо копипастить: - Доставляем пакет
yum install conntrack -y - curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/amd64/kubectl && chmod +x kubectl && mv -f kubectl /usr/local/bin/ && kubectl version
- KUBE_VERSION=v1.12.2
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/amd64/kubectl && chmod +x kubectl && mv -f kubectl /usr/local/bin/ && kubectl version
- curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && install minikube-linux-amd64 /usr/local/bin/minikube && minikube version
- minikube start --vm-driver=none
Проверяем
[root@minikub ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.2", GitCommit:"17c77c7898218073f14c8d573582e8d2313dc740", GitTreeState:"clean", BuildDate:"2018-10-24T06:54:59Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:50:46Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}
[root@minikub ~]# kubectl cluster-info
Kubernetes master is running at https://192.168.1.120:8443
KubeDNS is running at https://192.168.1.120:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@minikub ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikub Ready master 8m19s v1.18.0
[root@minikub ~]# kubectl get deployment --all-namespaces
NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE
kube-system coredns 2/2 2 2 8m33s
[root@minikub ~]# minikube status
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
ставим сеть:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
запускаем nginx ingres
minikube addons enable ingress
проверяем:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@minikub ~]#<strong> kubectl get pods --all-namespaces</strong> NAMESPACE NAME READY STATUS RESTARTS AGE kube-system calico-kube-controllers-5b8b769fcd-qmnms 1/1 Running 4 3d19h kube-system calico-node-2tjhc 1/1 Running 2 3d19h kube-system coredns-66bff467f8-dz6z5 1/1 Running 3 3d19h kube-system coredns-66bff467f8-tl4hk 1/1 Running 3 3d19h kube-system etcd-minikub 1/1 Running 2 3d19h kube-system kube-apiserver-minikub 1/1 Running 2 3d19h kube-system kube-controller-manager-minikub 1/1 Running 3 3d19h kube-system kube-proxy-75k6j 1/1 Running 2 3d19h kube-system kube-scheduler-minikub 1/1 Running 3 3d19h <strong>kube-system nginx-ingress-controller-6d57c87cb9-x4srv 1/1 Running 0 2m21s</strong> kube-system storage-provisioner 1/1 Running 3 3d19h |
==================================================
Запустим hello world чтоб проверить что всё работает.
1.создаём пространство имён в рамках которого будет проверка:
kubectl create namespace dev
2.создаём файл hello-app.yaml со следующим содержимым:
[codesyntax lang="php"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
apiVersion: apps/v1 kind: Deployment metadata: name: hello-app namespace: dev spec: selector: matchLabels: app: hello replicas: 3 template: metadata: labels: app: hello spec: containers: - name: hello image: "gcr.io/google-samples/hello-app:2.0" |
[/codesyntax]
деплоим:
kubectl create -f hello-app.yaml
3.создаём сервис, для этого в файл hello-app-service.yaml добавляем:
[codesyntax lang="php"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
apiVersion: v1 kind: Service metadata: name: hello-service namespace: dev labels: app: hello spec: type: ClusterIP selector: app: hello ports: - port: 80 targetPort: 8080 protocol: TCP |
[/codesyntax]
деплоим его:
kubectl create -f hello-app-service.yaml
4.создаём ingress объект, для этого в файл ingress.yml добавляем:
[codesyntax lang="php"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: test-ingress namespace: dev spec: rules: - host: test.ru http: paths: - backend: serviceName: hello-service servicePort: 80 |
[/codesyntax]
деплоим
kubectl create -f ingress.yml
5.теперь можно проверить:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[root@minikub ~]# <strong>kubectl get deployments -n dev</strong> NAME READY UP-TO-DATE AVAILABLE AGE hello-app 3/3 3 3 16m [root@minikub ~]# <strong>kubectl get pods --all-namespaces</strong> NAMESPACE NAME READY STATUS RESTARTS AGE dev hello-app-646fb5f544-22zkw 1/1 Running 0 17m dev hello-app-646fb5f544-65s7n 1/1 Running 0 17m dev hello-app-646fb5f544-pcjjg 1/1 Running 0 17m kube-system calico-kube-controllers-5b8b769fcd-qmnms 1/1 Running 4 3d19h kube-system calico-node-2tjhc 1/1 Running 2 3d19h kube-system coredns-66bff467f8-dz6z5 1/1 Running 3 3d20h kube-system coredns-66bff467f8-tl4hk 1/1 Running 3 3d20h kube-system etcd-minikub 1/1 Running 2 3d20h kube-system kube-apiserver-minikub 1/1 Running 2 3d20h kube-system kube-controller-manager-minikub 1/1 Running 3 3d20h kube-system kube-proxy-75k6j 1/1 Running 2 3d20h kube-system kube-scheduler-minikub 1/1 Running 3 3d20h kube-system nginx-ingress-controller-6d57c87cb9-x4srv 1/1 Running 0 22m kube-system storage-provisioner 1/1 Running 3 3d20h [root@minikub ~]# <strong>kubectl describe ingress -n dev</strong> Name: test-ingress Namespace: dev Address: 192.168.1.120 Default backend: default-http-backend:80 (<none>) Rules: Host Path Backends ---- ---- -------- test.ru hello-service:80 (<none>) Annotations: Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal CREATE 12m nginx-ingress-controller Ingress dev/test-ingress Normal UPDATE 11m nginx-ingress-controller Ingress dev/test-ingress |
обращаясь к домену:
http://test.ru/
мы получим примерно такой вывод:
1 2 3 |
Hello, world! Version: 2.0.0 Hostname: hello-app-646fb5f544-pcjjg |