You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.6 KiB
Markdown
97 lines
2.6 KiB
Markdown
# Kubernetes
|
|
|
|
- Terms
|
|
- pod : running container / instance. Normal a pod run a single container. However, a pod can also run more than one container
|
|
- node : virtual machine node
|
|
- cluster : private network cluster
|
|
- deployment : pod with auto scaling feature
|
|
- service : To use LoadBalancer feature. Thus, to allow pod accessible from localhost (before this all pod is only accessible within minikube)
|
|
- ClusterIP : IP adrress accessible within cluster only. NOT accessible from localhost
|
|
- ExternalIP : For actual cloud
|
|
- LoadBalancerIP :
|
|
|
|
|
|
|
|
- minikube : single master-slave Kubernetes cluster setup
|
|
```shell
|
|
$ minikube start drivers=kvm2
|
|
|
|
$ minikube status
|
|
|
|
# IP address of minikube
|
|
$ minikube ip
|
|
|
|
# ssh into minikube
|
|
# ssh docker@<minikubeIP>
|
|
# password : tcuser
|
|
$ minikube ssh
|
|
|
|
# inside minikube
|
|
$ docker ps
|
|
$ docker exec -it <container_id> sh
|
|
```
|
|
|
|
- kubectl : Kubernetes CLI
|
|
```shell
|
|
# create jenkins namespace
|
|
$ kubectl create namespace jenkins
|
|
|
|
# list existing namespaces
|
|
$ kubectl get namespaces
|
|
|
|
$ kubectl cluster-info
|
|
|
|
$ kubectl get node
|
|
|
|
$ kubectl get pods
|
|
|
|
# run nginx docker image
|
|
$ kubectl run nginx --image=nginx
|
|
$ kubectl get pods
|
|
$ kubectl describe pod nginx
|
|
|
|
# get pods container IP address
|
|
$ kubectl get pods -o wide
|
|
|
|
$ kubectl delete pod nginx
|
|
|
|
# deployment in order to do scaling
|
|
$ kubectl create deployment nginx-deployment --image=nginx
|
|
$ kubectl get deployments
|
|
$ kubectl get pods
|
|
$ kubectl describe deployment nginx-deployment
|
|
# show all running replicas
|
|
$ kubectl get pods -o wide
|
|
|
|
# create a service, expose internal port 80 to external 8080
|
|
$ kubectl expose deployment nginx-deployment --port=8080 --target-port=80
|
|
|
|
# get svc
|
|
$ kubectl get services
|
|
|
|
```
|
|
|
|
- Port forwarding
|
|
|
|
```shell
|
|
# Listen on port 8888 locally, forwarding to 5000 in the pod
|
|
kubectl port-forward pod/mypod 8888:5000
|
|
|
|
# Listen on port 8888 on all addresses, forwarding to 5000 in the pod
|
|
kubectl port-forward --address 0.0.0.0 pod/mypod 8888:5000
|
|
|
|
# Listen on a random port locally, forwarding to 5000 in the pod
|
|
kubectl port-forward pod/mypod :5000
|
|
|
|
# Listen on port 8888 on localhost and selected IP, forwarding to 5000 in the pod
|
|
kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888:5000
|
|
|
|
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
|
|
kubectl port-forward pod/mypod 5000 6000
|
|
|
|
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the deployment
|
|
kubectl port-forward deployment/mydeployment 5000 6000
|
|
|
|
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the service
|
|
kubectl port-forward service/myservice 5000 6000
|
|
``` |