AKS icon indicating copy to clipboard operation
AKS copied to clipboard

Question: Corporate environment, modifications to AKS nodes

Open eosfor opened this issue 8 years ago • 8 comments

We run private AKS cluster in our corporate environment (custom VNET, internal DNS, proxy etc, AD Domain etc). We need to apply modifications to the workers each time they are provisioned/upgraded. What is the best way if doing this?

Thanks in advance

eosfor avatar Aug 08 '18 19:08 eosfor

Any node-specific modifications should be done via DaemonSets.. For example you can use a boilerplate NGINX image mapped to the node drive and then make any modifications as part of the startup script for the container.

sujitdmello avatar Aug 09 '18 15:08 sujitdmello

Well, maybe I misunderstood the answer. Let me clarify something. For example I need to update a worker node (not a pod but node itself) with root certificates of my company's CAs, proxy server configuration and PAM to use inside the organization. I don't think any pod can update the node it is running on with files and configs, right? So the task is to bring the AKS worker node itself in-line with the corporate standard before we even run the pods on it.

If I'm wrong and it is possible to do with DaemonSet, may I ask you to point me to some sample, please?

Actually I thought about using some "event" raised at the moment, when AKS VM is up and fully operational. Which in turn should trigger some "automation", which will then put necessary configs to a VM. But it seems to me a bit tricky. Maybe there is a simpler way of achieving this, I don't know

eosfor avatar Aug 10 '18 11:08 eosfor

I don't think any pod can update the node it is running on with files and configs, right?

@eosfs It absolutely can. (Also why you should never run random third party containers and kube configs without review)

Its sort of a hack but it'll work. Its basically done by mounting the host paths inside the container.

Just so you have an idea, here's an example daemonset I use to set transparent_hugepage to disabled so redis stops complaining on my cluster ;)

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: thp-disable
  namespace: kube-system
spec:
  selector:
    matchLabels:
      name: thp-disable
  template:
    metadata:
      labels:
        name: thp-disable
    spec:
      restartPolicy: Always
      terminationGracePeriodSeconds: 1
      volumes:
        - name: host-sys
          hostPath:
            path: /sys
      initContainers:
        - name: disable-thp
          image: busybox
          volumeMounts:
            - name: host-sys
              mountPath: /host-sys
          command: ["sh", "-c", "echo never >/host-sys/kernel/mm/transparent_hugepage/enabled"]
      containers:
        - name: busybox
          image: busybox
          command: ["watch", "-n", "600", "cat", "/sys/kernel/mm/transparent_hugepage/enabled"]

For yourself you can either:

  1. Create a docker image with everything you need inside and a script to execute (which in your case might work out very neatly since you'll have a package with everything)
  2. Pass a command to an existing container like busybox here

If you want to execute commands on the node, you have to use the privileged flag on the container like this

        - name: disable-thp
          image: busybox
          securityContext:
            privileged: true

and then mount /usr/bin from the host into the container. From there you can execute the bash from that mounted path and its basically running on host

marekr avatar Aug 10 '18 13:08 marekr

Thanks @marker, will give it a try

eosfor avatar Aug 10 '18 13:08 eosfor

@eosfor just added a tiny tidbit up top on how to execute commands directly on host if you need to issue a reload command or something

marekr avatar Aug 10 '18 13:08 marekr

Thanks very much!

eosfor avatar Aug 10 '18 13:08 eosfor

We run a similar pattern where we use this node access to see kubelet logs and / or restart nodes (we don't have access to the Azure resources, only to Kube cluster).

I use this daemon set

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: debug
spec:
  selector:
    matchLabels:
      name: debug
  template:
    metadata:
      labels:
        name: debug
    spec:
      hostNetwork: true
      containers:
      - name: debug
        image: ubuntu
        command:
          - bash
          - "-c"
          - |
            echo "Running debug container"
            while true; do
              date
              sleep 24h
            done
        securityContext:
          privileged: true
        resources:
          limits:
            cpu: "200m"
            memory: "200Mi"
          requests:
            cpu: "20m"
            memory: "100Mi"
        volumeMounts:
        - name: node
          mountPath: /node
          readOnly: true
      volumes:
      - name: node
        hostPath:
          path: /

And then execute commands on the host (like journalctl -u kubelet or reboot as below)

$ kubectl exec $DEBUGPOD -- chroot /node /bin/bash -c "systemctl reboot"

This is probably very risky, so it's a last resort sort of thing when nodes are just not happy.

saykumar avatar Aug 10 '18 13:08 saykumar

how can I run a commnd "sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t", using the daemonset and hostpath you mentioned? I get the error, sudo:command not found error for the container

shivgu avatar Jun 12 '20 23:06 shivgu