Skip to content

Instantly share code, notes, and snippets.

@diegograssato
Last active April 29, 2021 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegograssato/536825e4212debc96861b0a3d715dab6 to your computer and use it in GitHub Desktop.
Save diegograssato/536825e4212debc96861b0a3d715dab6 to your computer and use it in GitHub Desktop.
Cluster with kind
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
helm repo update
helm install dashboard kubernetes-dashboard/kubernetes-dashboard -n kubernetes-dashboard --create-namespace
kubectl apply -f service-account.yaml
kubectl proxy
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:dashboard-kubernetes-dashboard:https/proxy/#/login
- Get secret
kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64
chmod +x ./kind
mv ./kind $HOME/.local/bin/kind
wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
- Edit
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
- --kubelet-insecure-tls
kubectl apply -f components.yaml
sleep 20
kubectl get deployment metrics-server -n kube-system
kubectl top pod --all-namespaces
kubectl top nodes
# Via helm
helm repo add stable https://charts.helm.sh/stable
helm update
helm upgrade metrics-server --install --set "args={--kubelet-insecure-tls, --kubelet-preferred-address-types=InternalIP}" stable/metrics-server --namespace kube-system
sleep 20
kubectl top pod --all-namespaces
kubectl top nodes
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/master/manifests/namespace.yaml
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/master/manifests/metallb.yaml
kubectl get pods -n metallb-system --watch
docker network inspect -f '{{.IPAM.Config}}' kind
metallb-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 172.26.255.200-172.26.255.250
kubectl apply -f metallb-configmap.yaml
- Edit dashboard port to LoadBalance
kubectl patch svc dashboard-kubernetes-dashboard -p '{"spec": {"ports": [{"port": 443,"targetPort": 8443}],"type": "LoadBalancer"}}' -n kubernetes-dashboard
- ou crie outro service
dashboard-loadbalancer.yml
---
apiVersion: v1
kind: Service
metadata:
name: kubernetes-dashboard-lb
namespace: kubernetes-dashboard
labels:
app.kubernetes.io/component: kubernetes-dashboard
app.kubernetes.io/instance: dashboard
app.kubernetes.io/managed-by: Helm
kubernetes.io/cluster-service: 'true'
annotations:
meta.helm.sh/release-name: dashboard
meta.helm.sh/release-namespace: kubernetes-dashboard
spec:
type: LoadBalancer
ports:
- port: 443
protocol: TCP
targetPort: 8443
selector:
app.kubernetes.io/component: kubernetes-dashboard
app.kubernetes.io/instance: dashboard
app.kubernetes.io/name: kubernetes-dashboard
kubectl apply -f dashboard-loadbalancer.yml
- Get new ip
kubectl -n kubernetes-dashboard get svc
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
cat <<EOF | kind create cluster --name multi-node --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
podSubnet: "10.244.0.0/16"
serviceSubnet: "10.96.0.0/12"
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 8080
protocol: TCP
- containerPort: 443
hostPort: 8443
protocol: TCP
- role: worker
- role: worker
- role: worker
EOF
kubectl apply -f https://kind.sigs.k8s.io/examples/ingress/usage.yaml
# should output "foo"
curl localhost:8080/foo
# should output "bar"
curl localhost:8080/bar
kind load docker-image my-image:1.0.0 --name multi-node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment